mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-07 07:16:54 +00:00
chore: move converter methods users v2 to separate converter package + add tests (#10567)
# Which Problems Are Solved As requested by @adlerhurst in https://github.com/zitadel/zitadel/pull/10415#discussion_r2298087711 , I am moving the refactoring of v2 user converter methods to a separate PR # How the Problems Are Solved Cherry-pick648c234caf# Additional Context Parent of https://github.com/zitadel/zitadel/pull/10415 (cherry picked from commitb604615cab)
This commit is contained in:
108
internal/api/grpc/user/v2/convert/machine_test.go
Normal file
108
internal/api/grpc/user/v2/convert/machine_test.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
||||
)
|
||||
|
||||
func Test_accessTokenTypeToPb(t *testing.T) {
|
||||
t.Parallel()
|
||||
tt := []struct {
|
||||
name string
|
||||
input domain.OIDCTokenType
|
||||
expected user.AccessTokenType
|
||||
}{
|
||||
{
|
||||
name: "Bearer token type",
|
||||
input: domain.OIDCTokenTypeBearer,
|
||||
expected: user.AccessTokenType_ACCESS_TOKEN_TYPE_BEARER,
|
||||
},
|
||||
{
|
||||
name: "JWT token type",
|
||||
input: domain.OIDCTokenTypeJWT,
|
||||
expected: user.AccessTokenType_ACCESS_TOKEN_TYPE_JWT,
|
||||
},
|
||||
{
|
||||
name: "Unknown token type returns Bearer",
|
||||
input: domain.OIDCTokenType(2),
|
||||
expected: user.AccessTokenType_ACCESS_TOKEN_TYPE_BEARER,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := accessTokenTypeToPb(tc.input)
|
||||
require.Equal(t, tc.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_machineToPb(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tt := []struct {
|
||||
name string
|
||||
input *query.Machine
|
||||
expected *user.MachineUser
|
||||
}{
|
||||
{
|
||||
name: "All fields set, Bearer token, HasSecret true",
|
||||
input: &query.Machine{
|
||||
Name: "machine1",
|
||||
Description: "desc",
|
||||
EncodedSecret: "secret",
|
||||
AccessTokenType: domain.OIDCTokenTypeBearer,
|
||||
},
|
||||
expected: &user.MachineUser{
|
||||
Name: "machine1",
|
||||
Description: "desc",
|
||||
HasSecret: true,
|
||||
AccessTokenType: user.AccessTokenType_ACCESS_TOKEN_TYPE_BEARER,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "No secret, JWT token",
|
||||
input: &query.Machine{
|
||||
Name: "machine2",
|
||||
Description: "desc2",
|
||||
EncodedSecret: "",
|
||||
AccessTokenType: domain.OIDCTokenTypeJWT,
|
||||
},
|
||||
expected: &user.MachineUser{
|
||||
Name: "machine2",
|
||||
Description: "desc2",
|
||||
HasSecret: false,
|
||||
AccessTokenType: user.AccessTokenType_ACCESS_TOKEN_TYPE_JWT,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Unknown token type, HasSecret false",
|
||||
input: &query.Machine{
|
||||
Name: "machine3",
|
||||
Description: "desc3",
|
||||
EncodedSecret: "",
|
||||
AccessTokenType: domain.OIDCTokenType(99),
|
||||
},
|
||||
expected: &user.MachineUser{
|
||||
Name: "machine3",
|
||||
Description: "desc3",
|
||||
HasSecret: false,
|
||||
AccessTokenType: user.AccessTokenType_ACCESS_TOKEN_TYPE_BEARER,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := machineToPb(tc.input)
|
||||
require.Equal(t, tc.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user