photoprism/internal/form/client_test.go
Michael Mayer 966c421cd4 Auth: Update internal/form/client_test.go #782 #808 #3943
Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-01-19 15:12:47 +01:00

42 lines
1.1 KiB
Go

package form
import (
"flag"
"testing"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli"
"github.com/photoprism/photoprism/pkg/authn"
)
func TestNewClient(t *testing.T) {
t.Run("Defaults", func(t *testing.T) {
client := NewClient()
assert.Equal(t, authn.ProviderClientCredentials, client.Provider())
assert.Equal(t, authn.MethodOAuth2, client.Method())
assert.Equal(t, "", client.Scope())
assert.Equal(t, "", client.Name())
})
}
func TestNewClientFromCli(t *testing.T) {
t.Run("Success", func(t *testing.T) {
globalSet := flag.NewFlagSet("test", 0)
globalSet.String("name", "Test", "")
globalSet.String("scope", "*", "")
globalSet.String("provider", "client_credentials", "")
globalSet.String("method", "totp", "")
app := cli.NewApp()
app.Version = "0.0.0"
c := cli.NewContext(app, globalSet, nil)
client := NewClientFromCli(c)
assert.Equal(t, authn.ProviderClientCredentials, client.Provider())
assert.Equal(t, authn.MethodTOTP, client.Method())
assert.Equal(t, "webdav", client.Scope())
assert.Equal(t, "Test", client.Name())
})
}