Tests: Add unit tests

This commit is contained in:
graciousgrey
2024-05-07 16:22:25 +02:00
parent 09ca932a88
commit ca52f0efa5
2 changed files with 126 additions and 0 deletions

View File

@@ -77,6 +77,28 @@ func TestOAuthCreateToken_Validate(t *testing.T) {
assert.NoError(t, m.Validate())
})
t.Run("UsernameRequired", func(t *testing.T) {
m := OAuthCreateToken{
GrantType: authn.GrantPassword,
Username: "",
Password: "abcdefg",
ClientName: "test",
Scope: "*",
}
assert.Error(t, m.Validate())
})
t.Run("UsernameTooLong", func(t *testing.T) {
m := OAuthCreateToken{
GrantType: authn.GrantPassword,
Username: "aaaaabbbbbccccdddddfffffrrrrrttttttyyyyssssssssssdddddllllloooooooooowerty",
Password: "abcdefg",
ClientName: "test",
Scope: "*",
}
assert.Error(t, m.Validate())
})
t.Run("PasswordRequired", func(t *testing.T) {
m := OAuthCreateToken{
GrantType: authn.GrantPassword,
@@ -86,6 +108,50 @@ func TestOAuthCreateToken_Validate(t *testing.T) {
Scope: "*",
}
assert.Error(t, m.Validate())
})
t.Run("PasswordTooLong", func(t *testing.T) {
m := OAuthCreateToken{
GrantType: authn.GrantPassword,
Username: "admin",
Password: "aaaaabbbbbccccdddddfffffrrrrrttttttyyyyssssssssssdddddllllloooooooooowerty",
ClientName: "test",
Scope: "*",
}
assert.Error(t, m.Validate())
})
t.Run("ClientNameRequired", func(t *testing.T) {
m := OAuthCreateToken{
GrantType: authn.GrantPassword,
Username: "admin",
Password: "cs5gfen1bgxz7s9i",
ClientName: "",
Scope: "*",
}
assert.Error(t, m.Validate())
})
t.Run("ScopeRequired", func(t *testing.T) {
m := OAuthCreateToken{
GrantType: authn.GrantPassword,
Username: "admin",
Password: "cs5gfen1bgxz7s9i",
ClientName: "test",
Scope: "",
}
assert.Error(t, m.Validate())
})
t.Run("InvalidGrantType", func(t *testing.T) {
m := OAuthCreateToken{
GrantType: "invalid",
Username: "admin",
Password: "cs5gfen1bgxz7s9i",
ClientName: "test",
Scope: "",
}
assert.Error(t, m.Validate())
})
}