auth/internal/domain/session.go

49 lines
1.4 KiB
Go
Raw Permalink 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/domain/challenge"
"source.toby3d.me/toby3d/auth/internal/domain/scope"
"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"`
Profile *Profile `json:"profile,omitempty"`
CodeChallengeMethod challenge.Method `json:"code_challenge_method,omitempty"`
CodeChallenge string `json:"code_challenge,omitempty"`
Code string `json:"-"`
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: challenge.PLAIN,
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{
scope.Email,
scope.Profile,
2022-01-29 17:50:45 +00:00
},
2022-01-08 10:52:55 +00:00
}
}