photoprism/pkg/authn/methods_test.go
Michael Mayer 713593da4e Auth: Add CLI command to create access tokens for apps #782 #808 #3943
You can now run "photoprism auth add" to create new client access tokens
that allow external applications to use the built-in REST API.

Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-01-05 16:31:07 +01:00

42 lines
1.4 KiB
Go

package authn
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMethodType_String(t *testing.T) {
assert.Equal(t, "default", MethodDefault.String())
assert.Equal(t, "basic", MethodBasic.String())
assert.Equal(t, "access_token", MethodAccessToken.String())
assert.Equal(t, "oauth2", MethodOAuth2.String())
assert.Equal(t, "oidc", MethodOIDC.String())
assert.Equal(t, "default", MethodUnknown.String())
}
func TestMethodType_IsDefault(t *testing.T) {
assert.Equal(t, true, MethodDefault.IsDefault())
assert.Equal(t, false, MethodBasic.IsDefault())
assert.Equal(t, false, MethodAccessToken.IsDefault())
assert.Equal(t, false, MethodOAuth2.IsDefault())
assert.Equal(t, false, MethodOIDC.IsDefault())
assert.Equal(t, true, MethodUnknown.IsDefault())
}
func TestMethodType_Pretty(t *testing.T) {
assert.Equal(t, "Default", MethodDefault.Pretty())
assert.Equal(t, "Basic", MethodBasic.Pretty())
assert.Equal(t, "Access Token", MethodAccessToken.Pretty())
assert.Equal(t, "OAuth2", MethodOAuth2.Pretty())
assert.Equal(t, "OIDC", MethodOIDC.Pretty())
assert.Equal(t, "Default", MethodUnknown.Pretty())
}
func TestMethod(t *testing.T) {
assert.Equal(t, MethodDefault, Method("default"))
assert.Equal(t, MethodBasic, Method("basic"))
assert.Equal(t, MethodAccessToken, Method("access_token"))
assert.Equal(t, MethodOAuth2, Method("oauth2"))
assert.Equal(t, MethodOIDC, Method("oidc"))
}