(t *testing.T)
| 545 | } |
| 546 | |
| 547 | func TestTokenExchange(t *testing.T) { |
| 548 | store := &mockStore{} |
| 549 | c := componenttest.NewComponent(t, &component.Config{ |
| 550 | ServiceBase: config.ServiceBase{ |
| 551 | HTTP: config.HTTP{ |
| 552 | Cookie: config.Cookie{ |
| 553 | HashKey: []byte("12345678123456781234567812345678"), |
| 554 | BlockKey: []byte("12345678123456781234567812345678"), |
| 555 | }, |
| 556 | }, |
| 557 | }, |
| 558 | }) |
| 559 | s, err := oauth.NewServer(c, store, oauth.Config{ |
| 560 | Mount: "/oauth", |
| 561 | UI: oauth.UIConfig{ |
| 562 | TemplateData: webui.TemplateData{ |
| 563 | SiteName: "The Things Network", |
| 564 | Title: "OAuth", |
| 565 | }, |
| 566 | }, |
| 567 | }, identityserver.GenerateCSPString) |
| 568 | if err != nil { |
| 569 | panic(err) |
| 570 | } |
| 571 | c.RegisterWeb(s) |
| 572 | componenttest.StartComponent(t, c) |
| 573 | |
| 574 | for _, tt := range []struct { |
| 575 | Name string |
| 576 | StoreSetup func(*mockStore) |
| 577 | StoreCheck func(*testing.T, *mockStore) |
| 578 | Method string |
| 579 | Path string |
| 580 | Body any |
| 581 | RequestSetup func(*http.Request) |
| 582 | ExpectedCode int |
| 583 | ExpectedBody string |
| 584 | }{ |
| 585 | { |
| 586 | Name: "Empty Grant Type", |
| 587 | Method: "POST", |
| 588 | Path: "/oauth/token", |
| 589 | Body: map[string]string{ |
| 590 | "grant_type": "", |
| 591 | }, |
| 592 | ExpectedCode: http.StatusBadRequest, |
| 593 | StoreCheck: func(t *testing.T, s *mockStore) { |
| 594 | a := assertions.New(t) |
| 595 | a.So(s.calls, should.NotContain, "GetAuthorizationCode") |
| 596 | a.So(s.calls, should.NotContain, "DeleteAuthorizationCode") |
| 597 | a.So(s.calls, should.NotContain, "CreateAccessToken") |
| 598 | }, |
| 599 | }, |
| 600 | { |
| 601 | Name: "Empty Authorization Code", |
| 602 | Method: "POST", |
| 603 | Path: "/oauth/token", |
| 604 | Body: map[string]string{ |
nothing calls this directly
no test coverage detected