Skip to content

Commit 109f340

Browse files
authored
fix: Use a case-insensitive organization name lookup (#156)
1 parent a7c7226 commit 109f340

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

github/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (c *Client) installationID(ctx context.Context, orgName string) (int, error
300300
}
301301

302302
for _, v := range instResult {
303-
if v.Account.Login == orgName {
303+
if strings.EqualFold(v.Account.Login, orgName) {
304304
return v.ID, nil
305305
}
306306
}

github/client_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"net/http/httptest"
10+
"strings"
1011
"testing"
1112
"time"
1213

@@ -321,6 +322,50 @@ func TestClient_Token(t *testing.T) {
321322
},
322323
},
323324
},
325+
{
326+
name: "OrgNameLookupIsCaseInsensitive",
327+
ctx: context.Background(),
328+
tokReq: &tokenRequest{OrgName: strings.ToLower(testOrgName1)},
329+
handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
330+
t.Helper()
331+
332+
switch r.Method {
333+
case http.MethodGet:
334+
assert.Equal(t, r.URL.Path, "/app/installations")
335+
assert.Assert(t, r.Header.Get("Authorization") != "")
336+
337+
w.Header().Set("Content-Type", "application/json")
338+
body, _ := json.Marshal([]map[string]any{
339+
{
340+
"id": testInsID1,
341+
"account": map[string]any{
342+
"login": strings.ToUpper(testOrgName1),
343+
},
344+
},
345+
})
346+
w.WriteHeader(http.StatusOK)
347+
w.Write(body)
348+
case http.MethodPost:
349+
assert.Equal(t, r.URL.Path, fmt.Sprintf("/%s", testPath))
350+
assert.Assert(t, r.Header.Get("Authorization") != "")
351+
352+
w.Header().Set("Content-Type", "application/json")
353+
body, _ := json.Marshal(map[string]any{
354+
"token": testToken,
355+
"expires_at": testTokenExp,
356+
})
357+
w.WriteHeader(http.StatusCreated)
358+
w.Write(body)
359+
}
360+
}),
361+
res: &logical.Response{
362+
Data: map[string]any{
363+
"token": testToken,
364+
"installation_id": testInsID1,
365+
"expires_at": testTokenExp,
366+
},
367+
},
368+
},
324369
{
325370
name: "OrgNameNotInstalled",
326371
ctx: context.Background(),

0 commit comments

Comments
 (0)