mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-23 16:27:35 +00:00
e22689c125
* cleanup todo * pass id token details to oidc * feat(oidc): id token for device authorization This changes updates to the newest oidc version, so the Device Authorization grant can return ID tokens when the scope `openid` is set. There is also some refactoring done, so that the eventstore can be queried directly when polling for state. The projection is cleaned up to a minimum with only data required for the login UI. * try to be explicit wit hthe timezone to fix github * pin oidc v3.8.0 * remove TBD entry
151 lines
2.5 KiB
Go
151 lines
2.5 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestDeviceAuthState_Exists(t *testing.T) {
|
|
tests := []struct {
|
|
s DeviceAuthState
|
|
want bool
|
|
}{
|
|
{
|
|
s: DeviceAuthStateUndefined,
|
|
want: false,
|
|
},
|
|
{
|
|
s: DeviceAuthStateInitiated,
|
|
want: true,
|
|
},
|
|
{
|
|
s: DeviceAuthStateApproved,
|
|
want: true,
|
|
},
|
|
{
|
|
s: DeviceAuthStateDenied,
|
|
want: true,
|
|
},
|
|
{
|
|
s: DeviceAuthStateExpired,
|
|
want: true,
|
|
},
|
|
{
|
|
s: deviceAuthStateCount,
|
|
want: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.s.String(), func(t *testing.T) {
|
|
if got := tt.s.Exists(); got != tt.want {
|
|
t.Errorf("DeviceAuthState.Exists() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDeviceAuthState_Done(t *testing.T) {
|
|
tests := []struct {
|
|
s DeviceAuthState
|
|
want bool
|
|
}{
|
|
{
|
|
s: DeviceAuthStateUndefined,
|
|
want: false,
|
|
},
|
|
{
|
|
s: DeviceAuthStateInitiated,
|
|
want: false,
|
|
},
|
|
{
|
|
s: DeviceAuthStateApproved,
|
|
want: true,
|
|
},
|
|
{
|
|
s: DeviceAuthStateDenied,
|
|
want: false,
|
|
},
|
|
{
|
|
s: DeviceAuthStateExpired,
|
|
want: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.s.String(), func(t *testing.T) {
|
|
if got := tt.s.Done(); got != tt.want {
|
|
t.Errorf("DeviceAuthState.Done() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDeviceAuthState_Denied(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
s DeviceAuthState
|
|
want bool
|
|
}{
|
|
{
|
|
s: DeviceAuthStateUndefined,
|
|
want: false,
|
|
},
|
|
{
|
|
s: DeviceAuthStateInitiated,
|
|
want: false,
|
|
},
|
|
{
|
|
s: DeviceAuthStateApproved,
|
|
want: false,
|
|
},
|
|
{
|
|
s: DeviceAuthStateDenied,
|
|
want: true,
|
|
},
|
|
{
|
|
s: DeviceAuthStateExpired,
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.s.Denied(); got != tt.want {
|
|
t.Errorf("DeviceAuthState.Denied() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDeviceAuthCanceled_State(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
c DeviceAuthCanceled
|
|
want DeviceAuthState
|
|
}{
|
|
{
|
|
name: "empty",
|
|
want: DeviceAuthStateUndefined,
|
|
},
|
|
{
|
|
name: "invalid",
|
|
c: "foo",
|
|
want: DeviceAuthStateUndefined,
|
|
},
|
|
{
|
|
name: "denied",
|
|
c: DeviceAuthCanceledDenied,
|
|
want: DeviceAuthStateDenied,
|
|
},
|
|
{
|
|
name: "expired",
|
|
c: DeviceAuthCanceledExpired,
|
|
want: DeviceAuthStateExpired,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.c.State(); got != tt.want {
|
|
t.Errorf("DeviceAuthCanceled.State() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|