MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestTokenExchange

Function TestTokenExchange

pkg/oauth/server_test.go:547–884  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

545}
546
547func 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{

Callers

nothing calls this directly

Calls 12

RegisterWebMethod · 0.95
resetMethod · 0.95
ServeHTTPMethod · 0.95
NewServerFunction · 0.92
NewMethod · 0.65
AddMethod · 0.65
RunMethod · 0.65
EncodeMethod · 0.65
MarshalMethod · 0.65
SetMethod · 0.65
StringMethod · 0.65
GetIdsMethod · 0.45

Tested by

no test coverage detected