2023-12-12 18:42:50 +01:00
|
|
|
package form
|
|
|
|
|
|
|
|
import (
|
2024-01-16 18:10:42 +01:00
|
|
|
"flag"
|
2023-12-12 18:42:50 +01:00
|
|
|
"testing"
|
|
|
|
|
2024-01-19 15:12:47 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-01-16 18:10:42 +01:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
2023-12-12 18:42:50 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/authn"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewClient(t *testing.T) {
|
|
|
|
t.Run("Defaults", func(t *testing.T) {
|
|
|
|
client := NewClient()
|
2024-01-19 14:41:08 +01:00
|
|
|
assert.Equal(t, authn.ProviderClientCredentials, client.Provider())
|
2023-12-12 18:42:50 +01:00
|
|
|
assert.Equal(t, authn.MethodOAuth2, client.Method())
|
|
|
|
assert.Equal(t, "", client.Scope())
|
2024-01-16 16:51:49 +01:00
|
|
|
assert.Equal(t, "", client.Name())
|
2023-12-12 18:42:50 +01:00
|
|
|
})
|
|
|
|
}
|
2024-01-16 18:10:42 +01:00
|
|
|
|
|
|
|
func TestNewClientFromCli(t *testing.T) {
|
|
|
|
t.Run("Success", func(t *testing.T) {
|
|
|
|
globalSet := flag.NewFlagSet("test", 0)
|
|
|
|
globalSet.String("name", "Test", "")
|
|
|
|
globalSet.String("scope", "*", "")
|
2024-01-19 14:41:08 +01:00
|
|
|
globalSet.String("provider", "client_credentials", "")
|
2024-01-16 18:10:42 +01:00
|
|
|
globalSet.String("method", "totp", "")
|
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Version = "0.0.0"
|
|
|
|
|
|
|
|
c := cli.NewContext(app, globalSet, nil)
|
|
|
|
|
|
|
|
client := NewClientFromCli(c)
|
2024-01-19 14:41:08 +01:00
|
|
|
assert.Equal(t, authn.ProviderClientCredentials, client.Provider())
|
2024-01-19 13:45:30 +01:00
|
|
|
assert.Equal(t, authn.MethodTOTP, client.Method())
|
2024-01-16 18:10:42 +01:00
|
|
|
assert.Equal(t, "webdav", client.Scope())
|
|
|
|
assert.Equal(t, "Test", client.Name())
|
|
|
|
})
|
|
|
|
}
|