|
7 | 7 | "fmt" |
8 | 8 | "net/http" |
9 | 9 | "net/http/httptest" |
| 10 | + "strings" |
10 | 11 | "testing" |
11 | 12 | "time" |
12 | 13 |
|
@@ -321,6 +322,50 @@ func TestClient_Token(t *testing.T) { |
321 | 322 | }, |
322 | 323 | }, |
323 | 324 | }, |
| 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 | + }, |
324 | 369 | { |
325 | 370 | name: "OrgNameNotInstalled", |
326 | 371 | ctx: context.Background(), |
|
0 commit comments