Skip to content

Commit

Permalink
Handle trailing slash of GitHub endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tenjaa committed Jul 19, 2021
1 parent b95007f commit 5dc5163
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func GenerateAccessToken(s *Source, now time.Time) (string, error) {

var endpoint string
if s.V3Endpoint != "" {
endpoint = s.V3Endpoint
endpoint = strings.TrimRight(s.V3Endpoint, "/")
} else {
endpoint = "https://api.github.com"
}
Expand Down
13 changes: 12 additions & 1 deletion authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,21 @@ func TestGenerateAccessToken(t *testing.T) {
},
expectedAccessToken: "v1.b71be873ad96e64a84025ae7bee7694a99cb4ba9",
},
{
description: "handle trailing slash",
source: resource.Source{
Repository: "itsdalmo/test-repository",
AppId: "69592",
PrivateKey: "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAv6oJaa+0BCOT0dITtJK6oPfrE2R0Iynofj/a/vq4rfAw2MJp\nXA5l6WbwmQhevSm8sIYNb2T32qLyRsVXwBo1J8ovIoTXiPdsV41D19tytjctnf+u\n0LncTo2JJR3ik7/Ynu5Id4zjnsn1pYqwLX4EFxgCuEKwdZutPyiY2J7wATfsTtOJ\nsLF8idQijG23i5Obs6AWCZcHOhvdgfYAUOxLv2WRkCG5O1aXYa6nqVn0AgRgKjaJ\nnAENEoG7O9OEWIcUiG30riQouxMHfj0bATCvYoj7a2tvn4CUqk+SBODyh3Fvi0oC\na/NCBYFeK/5uUNyXQHqWy7xEVRef5lC0XbrUVwIDAQABAoIBAFDdqhkIQ/iXFjAp\n5ZyDZ/CwiWNmN8X6UZiq0nhQSolA1SsvY4qunHsMrqiyql4/dNg5xwNf419A7t3D\nN5HavOC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a2OXicWpdjX3hqhXMvwspe9a1y9u7LPZwqJH\n9Kc7VaZP1iS4EIxEc+qx38HqdeiUBcqTMRam6k3mSwactBKCKDI=\n-----END RSA PRIVATE KEY-----\n",
V3Endpoint: ts.URL + "/",
},
expectedAccessToken: "v1.b71be873ad96e64a84025ae7bee7694a99cb4ba9",
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
got, _ := resource.GenerateAccessToken(&tt.source, time.Unix(1592691442, 0))
got, err := resource.GenerateAccessToken(&tt.source, time.Unix(1592691442, 0))
assert.Nil(t, err)
assert.Equal(t, tt.expectedAccessToken, got)
})
}
Expand Down

0 comments on commit 5dc5163

Please sign in to comment.