2022-01-08 10:52:55 +00:00
|
|
|
package domain
|
|
|
|
|
2022-01-29 17:50:45 +00:00
|
|
|
import (
|
2023-01-02 01:15:11 +00:00
|
|
|
"net/url"
|
2022-01-29 17:50:45 +00:00
|
|
|
"testing"
|
|
|
|
|
2024-05-06 15:58:14 +00:00
|
|
|
"source.toby3d.me/toby3d/auth/internal/domain/challenge"
|
2022-03-13 10:58:34 +00:00
|
|
|
"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 {
|
2024-05-06 15:58:14 +00:00
|
|
|
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 {
|
2022-02-01 17:27:48 +00:00
|
|
|
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{
|
2023-01-14 21:27:37 +00:00
|
|
|
ClientID: *TestClientID(tb),
|
2022-01-29 17:50:45 +00:00
|
|
|
Code: code,
|
|
|
|
CodeChallenge: "hackme",
|
2024-05-06 15:58:14 +00:00
|
|
|
CodeChallengeMethod: challenge.PLAIN,
|
2022-02-17 15:12:34 +00:00
|
|
|
Profile: TestProfile(tb),
|
2023-01-14 21:27:37 +00:00
|
|
|
Me: *TestMe(tb, "https://user.example.net/"),
|
2023-01-02 01:15:11 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|