auth/internal/domain/session.go

47 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 (
"net/url"
2022-01-29 17:50:45 +00:00
"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-12-26 14:09:34 +00:00
//nolint:tagliatelle
2022-01-08 10:52:55 +00:00
type Session struct {
ClientID ClientID `json:"client_id"`
RedirectURI *url.URL `json:"redirect_uri"`
Me Me `json:"me"`
2022-02-17 19:13:45 +00:00
Profile *Profile `json:"profile,omitempty"`
CodeChallengeMethod CodeChallengeMethod `json:"code_challenge_method,omitempty"`
CodeChallenge string `json:"code_challenge,omitempty"`
Code string `json:"-"`
2023-07-06 23:11:53 +00:00
Scope Scopes `json:"scope"`
2022-01-08 10:52:55 +00:00
}
2022-01-29 17:50:45 +00:00
// TestSession returns valid random generated session for tests.
2022-12-26 14:09:34 +00:00
//
//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/"),
RedirectURI: &url.URL{Scheme: "https", Host: "example.com", Path: "/callback"},
2022-01-29 17:50:45 +00:00
Scope: Scopes{
ScopeEmail,
ScopeProfile,
},
2022-01-08 10:52:55 +00:00
}
}