mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 11:58:02 +00:00
97 lines
1.8 KiB
Go
97 lines
1.8 KiB
Go
|
package oidc
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
||
|
|
||
|
"github.com/zitadel/zitadel/internal/domain"
|
||
|
)
|
||
|
|
||
|
func TestResponseModeToBusiness(t *testing.T) {
|
||
|
type args struct {
|
||
|
responseMode oidc.ResponseMode
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want domain.OIDCResponseMode
|
||
|
}{
|
||
|
{
|
||
|
name: "empty",
|
||
|
args: args{""},
|
||
|
want: domain.OIDCResponseModeUnspecified,
|
||
|
},
|
||
|
{
|
||
|
name: "invalid",
|
||
|
args: args{"foo"},
|
||
|
want: domain.OIDCResponseModeUnspecified,
|
||
|
},
|
||
|
{
|
||
|
name: "query",
|
||
|
args: args{oidc.ResponseModeQuery},
|
||
|
want: domain.OIDCResponseModeQuery,
|
||
|
},
|
||
|
{
|
||
|
name: "fragment",
|
||
|
args: args{oidc.ResponseModeFragment},
|
||
|
want: domain.OIDCResponseModeFragment,
|
||
|
},
|
||
|
{
|
||
|
name: "post_form",
|
||
|
args: args{oidc.ResponseModeFormPost},
|
||
|
want: domain.OIDCResponseModeFormPost,
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
got := ResponseModeToBusiness(tt.args.responseMode)
|
||
|
assert.Equal(t, tt.want, got)
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestResponseModeToOIDC(t *testing.T) {
|
||
|
type args struct {
|
||
|
responseMode domain.OIDCResponseMode
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want oidc.ResponseMode
|
||
|
}{
|
||
|
{
|
||
|
name: "unspecified",
|
||
|
args: args{domain.OIDCResponseModeUnspecified},
|
||
|
want: "",
|
||
|
},
|
||
|
{
|
||
|
name: "invalid",
|
||
|
args: args{99},
|
||
|
want: "",
|
||
|
},
|
||
|
{
|
||
|
name: "query",
|
||
|
args: args{domain.OIDCResponseModeQuery},
|
||
|
want: oidc.ResponseModeQuery,
|
||
|
},
|
||
|
{
|
||
|
name: "fragment",
|
||
|
args: args{domain.OIDCResponseModeFragment},
|
||
|
want: oidc.ResponseModeFragment,
|
||
|
},
|
||
|
{
|
||
|
name: "form_post",
|
||
|
args: args{domain.OIDCResponseModeFormPost},
|
||
|
want: oidc.ResponseModeFormPost,
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
got := ResponseModeToOIDC(tt.args.responseMode)
|
||
|
assert.Equal(t, tt.want, got)
|
||
|
})
|
||
|
}
|
||
|
}
|