2024-01-05 16:31:07 +01:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-01-29 13:54:50 +01:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/unix"
|
2024-01-05 16:31:07 +01:00
|
|
|
)
|
|
|
|
|
2024-01-19 18:10:01 +01:00
|
|
|
func TestNewClientAuthentication(t *testing.T) {
|
2024-01-05 16:31:07 +01:00
|
|
|
t.Run("Anonymous", func(t *testing.T) {
|
2024-01-29 13:54:50 +01:00
|
|
|
sess := NewClientAuthentication("Anonymous", unix.Day, "metrics", nil)
|
2024-01-05 16:31:07 +01:00
|
|
|
|
|
|
|
if sess == nil {
|
|
|
|
t.Fatal("session must not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("sess: %#v", sess)
|
|
|
|
})
|
|
|
|
t.Run("Alice", func(t *testing.T) {
|
|
|
|
user := FindUserByName("alice")
|
|
|
|
|
|
|
|
if user == nil {
|
|
|
|
t.Fatal("user must not be nil")
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:50 +01:00
|
|
|
sess := NewClientAuthentication("alice", unix.Day, "metrics", user)
|
2024-01-05 16:31:07 +01:00
|
|
|
|
|
|
|
if sess == nil {
|
|
|
|
t.Fatal("session must not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("sess: %#v", sess)
|
|
|
|
})
|
|
|
|
t.Run("NoScope", func(t *testing.T) {
|
|
|
|
user := FindUserByName("alice")
|
|
|
|
|
|
|
|
if user == nil {
|
|
|
|
t.Fatal("user must not be nil")
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:50 +01:00
|
|
|
sess := NewClientAuthentication("alice", unix.Day, "", user)
|
2024-01-05 16:31:07 +01:00
|
|
|
|
|
|
|
if sess == nil {
|
|
|
|
t.Fatal("session must not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("sess: %#v", sess)
|
|
|
|
})
|
|
|
|
t.Run("NoLifetime", func(t *testing.T) {
|
|
|
|
user := FindUserByName("alice")
|
|
|
|
|
|
|
|
if user == nil {
|
|
|
|
t.Fatal("user must not be nil")
|
|
|
|
}
|
|
|
|
|
2024-01-19 18:10:01 +01:00
|
|
|
sess := NewClientAuthentication("", 0, "metrics", user)
|
2024-01-05 16:31:07 +01:00
|
|
|
|
|
|
|
if sess == nil {
|
|
|
|
t.Fatal("session must not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("sess: %#v", sess)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-01-19 18:10:01 +01:00
|
|
|
func TestAddClientAuthentication(t *testing.T) {
|
2024-01-05 16:31:07 +01:00
|
|
|
t.Run("Anonymous", func(t *testing.T) {
|
2024-01-29 13:54:50 +01:00
|
|
|
sess, err := AddClientAuthentication("", unix.Day, "metrics", nil)
|
2024-01-05 16:31:07 +01:00
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
if sess == nil {
|
|
|
|
t.Fatal("session must not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("sess: %#v", sess)
|
|
|
|
})
|
|
|
|
t.Run("Alice", func(t *testing.T) {
|
|
|
|
user := FindUserByName("alice")
|
|
|
|
|
|
|
|
if user == nil {
|
|
|
|
t.Fatal("user must not be nil")
|
|
|
|
}
|
|
|
|
|
2024-01-29 13:54:50 +01:00
|
|
|
sess, err := AddClientAuthentication("My Client App Token", unix.Day, "metrics", user)
|
2024-01-05 16:31:07 +01:00
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
if sess == nil {
|
|
|
|
t.Fatal("session must not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("sess: %#v", sess)
|
|
|
|
})
|
|
|
|
}
|