mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-07 07:16:54 +00:00
fix: review changes
This commit is contained in:
@@ -5,6 +5,7 @@ package user_test
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -192,7 +193,9 @@ func TestServer_AddPersonalAccessToken(t *testing.T) {
|
||||
OrgId: orgResp.GetOrganizationId(),
|
||||
},
|
||||
},
|
||||
PersonalAccessToken: &user.SetPersonalAccessToken{},
|
||||
PersonalAccessToken: &user.SetPersonalAccessToken{
|
||||
ExpirationDate: timestamppb.New(time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC)),
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &resource_object.Details{
|
||||
@@ -205,7 +208,7 @@ func TestServer_AddPersonalAccessToken(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pat add, generated, ok",
|
||||
name: "pat add, expirationdate invalid",
|
||||
ctx: isolatedIAMOwnerCTX,
|
||||
dep: func(req *user.AddPersonalAccessTokenRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
@@ -218,17 +221,11 @@ func TestServer_AddPersonalAccessToken(t *testing.T) {
|
||||
OrgId: orgResp.GetOrganizationId(),
|
||||
},
|
||||
},
|
||||
PersonalAccessToken: &user.SetPersonalAccessToken{},
|
||||
},
|
||||
res: res{
|
||||
want: &resource_object.Details{
|
||||
Changed: timestamppb.Now(),
|
||||
Owner: &object.Owner{
|
||||
Type: object.OwnerType_OWNER_TYPE_ORG,
|
||||
Id: orgResp.GetOrganizationId(),
|
||||
},
|
||||
PersonalAccessToken: &user.SetPersonalAccessToken{
|
||||
ExpirationDate: timestamppb.New(time.Date(2020, time.December, 31, 23, 59, 59, 0, time.UTC)),
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -5,6 +5,7 @@ package user_test
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -16,6 +17,8 @@ import (
|
||||
user "github.com/zitadel/zitadel/pkg/grpc/resources/user/v3alpha"
|
||||
)
|
||||
|
||||
var publicKeyExample = []byte("-----BEGIN PUBLIC KEY-----\nMIICITANBgkqhkiG9w0BAQEFAAOCAg4AMIICCQKCAgB5tWxwCGRloCqvpgI2ZXPl\nxQ+WZbQPuHTqAxwbXbsKOJoAAq16iHmzriLKpqVDxRUXqTH3cY0P0A1IZbCBB2gG\nyq3Lk08sR5ute+MEQ+QibX2qpk+mccRr+eP6B1otcyBWxRhZ/YtWphDpZ4GCb4oN\nAzTIebU0ztlu1OOnDDSEEhwScu2LhG40bx4hVU8XNgIqEjxiR61J89vfZpCmn0Rl\nsqYvmX9sqtqPokdsKl3LPItRyDAJMG0uhwwGKsHffDNeLDZN1OCZE/ZS7USarJQH\nbtGeqFQKsCL33xsKbNL+QjnAhqHW09bMdwofJvlwYLfL0rGJQr5aVCaERAfKAOE6\npy0nVkEJsRLxvdx/ZbTtZdCBk/LiznkE1xp9J02obQ+kWHtdUYxM1OSJqPRGQpbS\nZTxurdBQ43gRjO07iWNV9CB0i6QN2GtDBmHVb48i6aPdA++uJqnPYzy46FWA3KMA\nSlxiZ1RDcGH+fN9uklC2cwAurctAxed3Me2RYGdxl813udeV4Ef3qaiV2dix/pKA\nvN1KIfPTpTdULCDBLjtaAYflJ2WYXHeWMJMMC4oJc3bcKpA4mWjZibZ3pSGX/STQ\nXwHUtKsGlrVBSeqjjILVpH+2G0rusrqkGOlPKN+qOIsnwJf9x47v+xEw1slqdDWm\n+x3gc+8m9oowCcq20OeNTQIDAQAB\n-----END PUBLIC KEY-----")
|
||||
|
||||
func TestServer_AddPublicKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
instance := integration.NewInstance(CTX)
|
||||
@@ -60,7 +63,7 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_GeneratedKey{GeneratedKey: &user.GeneratedKey{}},
|
||||
Type: &user.SetPublicKey_GenerateKey{GenerateKey: &user.GenerateKey{}},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
@@ -80,7 +83,7 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_GeneratedKey{GeneratedKey: &user.GeneratedKey{}},
|
||||
Type: &user.SetPublicKey_GenerateKey{GenerateKey: &user.GenerateKey{}},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
@@ -105,6 +108,26 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "publickey add, publickey invalid format",
|
||||
ctx: instance.WithAuthorization(CTX, integration.UserTypeLogin),
|
||||
dep: func(req *user.AddPublicKeyRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
req.Id = userResp.GetDetails().GetId()
|
||||
return nil
|
||||
},
|
||||
req: &user.AddPublicKeyRequest{
|
||||
Organization: &object.Organization{
|
||||
Property: &object.Organization_OrgId{
|
||||
OrgId: orgResp.GetOrganizationId(),
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_PublicKey{PublicKey: &user.ProvidedPublicKey{PublicKey: []byte("invalid")}},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "publickey add, user not existing in org",
|
||||
ctx: isolatedIAMOwnerCTX,
|
||||
@@ -120,7 +143,7 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_GeneratedKey{GeneratedKey: &user.GeneratedKey{}},
|
||||
Type: &user.SetPublicKey_GenerateKey{GenerateKey: &user.GenerateKey{}},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
@@ -136,7 +159,7 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
Id: "notexisting",
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_GeneratedKey{GeneratedKey: &user.GeneratedKey{}},
|
||||
Type: &user.SetPublicKey_GenerateKey{GenerateKey: &user.GenerateKey{}},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
@@ -156,7 +179,7 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_GeneratedKey{GeneratedKey: &user.GeneratedKey{}},
|
||||
Type: &user.SetPublicKey_PublicKey{PublicKey: &user.ProvidedPublicKey{PublicKey: publicKeyExample}},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -179,7 +202,7 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
req: &user.AddPublicKeyRequest{
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_GeneratedKey{GeneratedKey: &user.GeneratedKey{}},
|
||||
Type: &user.SetPublicKey_PublicKey{PublicKey: &user.ProvidedPublicKey{PublicKey: publicKeyExample}},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -192,6 +215,27 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "publickey add, expirationdate invalid",
|
||||
ctx: isolatedIAMOwnerCTX,
|
||||
dep: func(req *user.AddPublicKeyRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
req.Id = userResp.GetDetails().GetId()
|
||||
return nil
|
||||
},
|
||||
req: &user.AddPublicKeyRequest{
|
||||
Organization: &object.Organization{
|
||||
Property: &object.Organization_OrgId{
|
||||
OrgId: orgResp.GetOrganizationId(),
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
ExpirationDate: timestamppb.New(time.Date(2020, time.December, 31, 23, 59, 59, 0, time.UTC)),
|
||||
Type: &user.SetPublicKey_PublicKey{PublicKey: &user.ProvidedPublicKey{PublicKey: publicKeyExample}},
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "publickey add, expirationdate, ok",
|
||||
ctx: isolatedIAMOwnerCTX,
|
||||
@@ -207,7 +251,8 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_PublicKey{PublicKey: &user.ProvidedPublicKey{PublicKey: []byte(gofakeit.BitcoinPrivateKey())}},
|
||||
ExpirationDate: timestamppb.New(time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC)),
|
||||
Type: &user.SetPublicKey_PublicKey{PublicKey: &user.ProvidedPublicKey{PublicKey: publicKeyExample}},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -235,7 +280,7 @@ func TestServer_AddPublicKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
PublicKey: &user.SetPublicKey{
|
||||
Type: &user.SetPublicKey_GeneratedKey{GeneratedKey: &user.GeneratedKey{}},
|
||||
Type: &user.SetPublicKey_GenerateKey{GenerateKey: &user.GenerateKey{}},
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -301,7 +346,7 @@ func TestServer_DeletePublicKey(t *testing.T) {
|
||||
dep: func(req *user.RemovePublicKeyRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
req.Id = userResp.GetDetails().GetId()
|
||||
publickeyResp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), userResp.GetDetails().GetId(), []byte(gofakeit.BitcoinPrivateKey()))
|
||||
publickeyResp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), userResp.GetDetails().GetId(), publicKeyExample)
|
||||
req.PublicKeyId = publickeyResp.GetPublicKeyId()
|
||||
return nil
|
||||
},
|
||||
@@ -320,7 +365,7 @@ func TestServer_DeletePublicKey(t *testing.T) {
|
||||
dep: func(req *user.RemovePublicKeyRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
req.Id = userResp.GetDetails().GetId()
|
||||
publickeyResp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), userResp.GetDetails().GetId(), []byte(gofakeit.BitcoinPrivateKey()))
|
||||
publickeyResp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), userResp.GetDetails().GetId(), publicKeyExample)
|
||||
req.PublicKeyId = publickeyResp.GetPublicKeyId()
|
||||
return nil
|
||||
},
|
||||
@@ -396,7 +441,7 @@ func TestServer_DeletePublicKey(t *testing.T) {
|
||||
dep: func(req *user.RemovePublicKeyRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
req.Id = userResp.GetDetails().GetId()
|
||||
publickeyResp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), userResp.GetDetails().GetId(), []byte(gofakeit.BitcoinPrivateKey()))
|
||||
publickeyResp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), userResp.GetDetails().GetId(), publicKeyExample)
|
||||
req.PublicKeyId = publickeyResp.GetPublicKeyId()
|
||||
return nil
|
||||
},
|
||||
@@ -423,7 +468,7 @@ func TestServer_DeletePublicKey(t *testing.T) {
|
||||
dep: func(req *user.RemovePublicKeyRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
req.Id = userResp.GetDetails().GetId()
|
||||
resp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), req.Id, []byte(gofakeit.BitcoinPrivateKey()))
|
||||
resp := instance.AddAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), req.Id, publicKeyExample)
|
||||
req.PublicKeyId = resp.GetPublicKeyId()
|
||||
instance.RemoveAuthenticatorPublicKey(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), req.Id, req.PublicKeyId)
|
||||
return nil
|
||||
|
||||
@@ -251,29 +251,6 @@ func TestServer_AddUsername(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "username add, already existing",
|
||||
ctx: isolatedIAMOwnerCTX,
|
||||
dep: func(req *user.AddUsernameRequest) error {
|
||||
userResp := instance.CreateSchemaUser(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), schemaResp.GetDetails().GetId(), []byte("{\"name\": \"user\"}"))
|
||||
req.Id = userResp.GetDetails().GetId()
|
||||
username := gofakeit.Username()
|
||||
instance.AddAuthenticatorUsername(isolatedIAMOwnerCTX, orgResp.GetOrganizationId(), req.Id, username, false)
|
||||
req.Username.Username = username
|
||||
return nil
|
||||
},
|
||||
req: &user.AddUsernameRequest{
|
||||
Organization: &object.Organization{
|
||||
Property: &object.Organization_OrgId{
|
||||
OrgId: orgResp.GetOrganizationId(),
|
||||
},
|
||||
},
|
||||
Username: &user.SetUsername{
|
||||
IsOrganizationSpecific: false,
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "username add, isOrgSpecific, already existing",
|
||||
ctx: isolatedIAMOwnerCTX,
|
||||
|
||||
@@ -37,16 +37,16 @@ func addPublicKeyRequestToAddPublicKey(req *user.AddPublicKeyRequest) *command.A
|
||||
}
|
||||
}
|
||||
|
||||
func setPublicKeyToAddPublicKey(req *user.SetPublicKey) *command.PublicKey {
|
||||
if req == nil {
|
||||
func setPublicKeyToAddPublicKey(set *user.SetPublicKey) *command.PublicKey {
|
||||
if set == nil {
|
||||
return nil
|
||||
}
|
||||
expDate := time.Time{}
|
||||
if req.GetExpirationDate() != nil {
|
||||
expDate = req.GetExpirationDate().AsTime()
|
||||
if set.GetExpirationDate() != nil {
|
||||
expDate = set.GetExpirationDate().AsTime()
|
||||
}
|
||||
return &command.PublicKey{
|
||||
PublicKey: req.GetPublicKey().GetPublicKey(),
|
||||
PublicKey: set.GetPublicKey().GetPublicKey(),
|
||||
ExpirationDate: expDate,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user