auth/internal/domain/session.go

45 lines
1.3 KiB
Go
Raw Normal View History

2022-01-08 10:52:55 +00:00
package domain
2022-01-29 17:50:45 +00:00
import (
"testing"
"source.toby3d.me/toby3d/auth/internal/random"
2022-01-29 17:50:45 +00:00
)
2022-01-08 10:52:55 +00:00
2022-02-17 19:13:45 +00:00
//nolint: tagliatelle
2022-01-08 10:52:55 +00:00
type Session struct {
2022-02-17 19:13:45 +00:00
ClientID *ClientID `json:"client_id"`
RedirectURI *URL `json:"redirect_uri"`
Me *Me `json:"me"`
Profile *Profile `json:"profile,omitempty"`
Scope Scopes `json:"scope"`
CodeChallengeMethod CodeChallengeMethod `json:"code_challenge_method,omitempty"`
CodeChallenge string `json:"code_challenge,omitempty"`
Code string `json:"-"`
2022-01-08 10:52:55 +00:00
}
2022-01-29 17:50:45 +00:00
// TestSession returns valid random generated session for tests.
//nolint: gomnd // testing domain can contains non-standart values
2022-01-08 10:52:55 +00:00
func TestSession(tb testing.TB) *Session {
tb.Helper()
2022-01-29 17:50:45 +00:00
code, err := random.String(24)
2022-01-30 17:49:25 +00:00
if err != nil {
tb.Fatal(err)
2022-01-30 17:49:25 +00:00
}
2022-01-29 17:50:45 +00:00
2022-01-08 10:52:55 +00:00
return &Session{
ClientID: TestClientID(tb),
2022-01-29 17:50:45 +00:00
Code: code,
CodeChallenge: "hackme",
CodeChallengeMethod: CodeChallengeMethodPLAIN,
Profile: TestProfile(tb),
Me: TestMe(tb, "https://user.example.net/"),
2022-01-08 10:52:55 +00:00
RedirectURI: TestURL(tb, "https://example.com/callback"),
2022-01-29 17:50:45 +00:00
Scope: Scopes{
ScopeEmail,
ScopeProfile,
},
2022-01-08 10:52:55 +00:00
}
}