auth/internal/domain/session.go

44 lines
1015 B
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/website/indieauth/internal/random"
)
2022-01-08 10:52:55 +00:00
type Session struct {
ClientID *ClientID
RedirectURI *URL
Me *Me
Profile *Profile
2022-01-08 10:52:55 +00:00
Scope Scopes
CodeChallengeMethod CodeChallengeMethod
2022-01-08 10:52:55 +00:00
CodeChallenge string
Code string
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
}
}