fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! added first event

This commit is contained in:
Iraq Jaber
2025-07-31 13:32:02 +01:00
parent 5ab959a6c1
commit 4f4ae3e6ea
5 changed files with 343 additions and 139 deletions

View File

@@ -18,7 +18,7 @@ const (
IDPTypeOAuth
IDPTypeLDAP
IDPTypeAzure
IDPTypeGitHub
IDPTypeGithub
IDPTypeGitHubEnterprise
IDPTypeGitLab
IDPTypeGitLabSelfHosted
@@ -93,7 +93,6 @@ type IDPOIDC struct {
}
type JWT struct {
IDPConfigID string `json:"idpConfigId"`
JWTEndpoint string `json:"jwtEndpoint,omitempty"`
Issuer string `json:"issuer,omitempty"`
KeysEndpoint string `json:"keysEndpoint,omitempty"`
@@ -106,8 +105,6 @@ type IDPJWT struct {
}
type OAuth struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
ClientID string `json:"clientId,omitempty"`
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
@@ -133,8 +130,6 @@ const (
)
type Azure struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ClientID string `json:"client_id,omitempty"`
ClientSecret *crypto.CryptoValue `json:"client_secret,omitempty"`
Scopes []string `json:"scopes,omitempty"`
@@ -148,8 +143,6 @@ type IDPOAzureAD struct {
}
type Google struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
ClientID string `json:"clientId"`
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
Scopes []string `json:"scopes,omitempty"`
@@ -160,6 +153,17 @@ type IDPGoogle struct {
Google
}
type Github struct {
ClientID string `json:"clientId"`
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
Scopes []string `json:"scopes,omitempty"`
}
type IDPGithub struct {
*IdentityProvider
Github
}
// IDPIdentifierCondition is used to help specify a single identity_provider,
// it will either be used as the identity_provider ID or identity_provider name,
// as identity_provider can be identified either using (instanceID + OrgID + ID) OR (instanceID + OrgID + name)
@@ -235,4 +239,5 @@ type IDProviderRepository interface {
GetOAzureAD(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPOAzureAD, error)
GetGoogle(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGoogle, error)
GetGithub(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGithub, error)
}

View File

@@ -30,7 +30,7 @@ func _IDPTypeNoOp() {
_ = x[IDPTypeOAuth-(3)]
_ = x[IDPTypeLDAP-(4)]
_ = x[IDPTypeAzure-(5)]
_ = x[IDPTypeGitHub-(6)]
_ = x[IDPTypeGithub-(6)]
_ = x[IDPTypeGitHubEnterprise-(7)]
_ = x[IDPTypeGitLab-(8)]
_ = x[IDPTypeGitLabSelfHosted-(9)]
@@ -39,7 +39,7 @@ func _IDPTypeNoOp() {
_ = x[IDPTypeSAML-(12)]
}
var _IDPTypeValues = []IDPType{IDPTypeUnspecified, IDPTypeOIDC, IDPTypeJWT, IDPTypeOAuth, IDPTypeLDAP, IDPTypeAzure, IDPTypeGitHub, IDPTypeGitHubEnterprise, IDPTypeGitLab, IDPTypeGitLabSelfHosted, IDPTypeGoogle, IDPTypeApple, IDPTypeSAML}
var _IDPTypeValues = []IDPType{IDPTypeUnspecified, IDPTypeOIDC, IDPTypeJWT, IDPTypeOAuth, IDPTypeLDAP, IDPTypeAzure, IDPTypeGithub, IDPTypeGitHubEnterprise, IDPTypeGitLab, IDPTypeGitLabSelfHosted, IDPTypeGoogle, IDPTypeApple, IDPTypeSAML}
var _IDPTypeNameToValueMap = map[string]IDPType{
_IDPTypeName[0:11]: IDPTypeUnspecified,
@@ -54,8 +54,8 @@ var _IDPTypeNameToValueMap = map[string]IDPType{
_IDPTypeLowerName[23:27]: IDPTypeLDAP,
_IDPTypeName[27:32]: IDPTypeAzure,
_IDPTypeLowerName[27:32]: IDPTypeAzure,
_IDPTypeName[32:38]: IDPTypeGitHub,
_IDPTypeLowerName[32:38]: IDPTypeGitHub,
_IDPTypeName[32:38]: IDPTypeGithub,
_IDPTypeLowerName[32:38]: IDPTypeGithub,
_IDPTypeName[38:54]: IDPTypeGitHubEnterprise,
_IDPTypeLowerName[38:54]: IDPTypeGitHubEnterprise,
_IDPTypeName[54:60]: IDPTypeGitLab,

View File

@@ -405,7 +405,6 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
assert.Equal(t, domain.IDPTypeJWT.String(), jwt.Type)
// jwt
assert.Equal(t, addJWT.IdpId, jwt.IDPConfigID)
assert.Equal(t, "jwtEndpoint", jwt.JWTEndpoint)
assert.Equal(t, "issuer", jwt.Issuer)
assert.Equal(t, "keyEndpoint", jwt.KeysEndpoint)
@@ -443,7 +442,6 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
assert.Equal(t, domain.IDPTypeJWT.String(), jwt.Type)
// jwt
assert.Equal(t, addJWT.IdpId, jwt.IDPConfigID)
assert.Equal(t, "jwtEndpoint", jwt.JWTEndpoint)
assert.Equal(t, "issuer", jwt.Issuer)
assert.Equal(t, "keyEndpoint", jwt.KeysEndpoint)
@@ -476,7 +474,6 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
assert.WithinRange(t, updateJWT.UpdatedAt, beforeCreate, afterCreate)
// jwt
assert.Equal(t, addJWT.IdpId, updateJWT.IDPConfigID)
assert.Equal(t, "new_jwtEndpoint", updateJWT.JWTEndpoint)
assert.Equal(t, "new_issuer", updateJWT.Issuer)
assert.Equal(t, "new_keyEndpoint", updateJWT.KeysEndpoint)
@@ -1095,8 +1092,8 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
// event instance.idp.azure.added
// idp
assert.Equal(t, addAzure.Id, azure.IdentityProvider.ID)
assert.Equal(t, name, azure.IdentityProvider.Name)
assert.Equal(t, addAzure.Id, azure.ID)
assert.Equal(t, name, azure.Name)
assert.Equal(t, "clientId", azure.ClientID)
assert.NotNil(t, azure.ClientSecret)
@@ -1147,6 +1144,7 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
assert.Equal(t, addAzure.Id, azure.IdentityProvider.ID)
}, retryDuration, tick)
name = "new_" + name
// change azure
beforeCreate := time.Now().Add(-1 * time.Second)
_, err = AdminClient.UpdateAzureADProvider(CTX, &admin.UpdateAzureADProviderRequest{
@@ -1196,4 +1194,122 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
assert.WithinRange(t, updateAzure.UpdatedAt, beforeCreate, afterCreate)
}, retryDuration, tick)
})
t.Run("test instance idp github added reduces", func(t *testing.T) {
name := gofakeit.Name()
// add github
beforeCreate := time.Now()
addGithub, err := AdminClient.AddGitHubProvider(CTX, &admin.AddGitHubProviderRequest{
Name: name,
ClientId: "clientId",
ClientSecret: "clientSecret",
Scopes: []string{"scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: false,
IsCreationAllowed: false,
IsAutoCreation: false,
IsAutoUpdate: false,
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
},
})
afterCreate := time.Now()
require.NoError(t, err)
idpRepo := repository.IDProviderRepository(pool)
// check values for github
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Second*5)
assert.EventuallyWithT(t, func(t *assert.CollectT) {
github, err := idpRepo.GetGithub(CTX, idpRepo.IDCondition(addGithub.Id), instanceID, nil)
require.NoError(t, err)
// event instance.idp.github.added
// idp
assert.Equal(t, addGithub.Id, github.ID)
assert.Equal(t, name, github.Name)
assert.Equal(t, "clientId", github.ClientID)
assert.NotNil(t, github.ClientSecret)
assert.Equal(t, domain.IDPTypeGithub.String(), github.Type)
assert.Equal(t, []string{"scope"}, github.Scopes)
assert.Equal(t, false, github.AllowLinking)
assert.Equal(t, false, github.AllowCreation)
assert.Equal(t, false, github.AllowAutoUpdate)
assert.Equal(t, domain.IDPAutoLinkingOptionUserName.String(), github.AllowAutoLinking)
assert.WithinRange(t, github.UpdatedAt, beforeCreate, afterCreate)
}, retryDuration, tick)
})
t.Run("test instance idp github changed reduces", func(t *testing.T) {
name := gofakeit.Name()
// add github
addGithub, err := AdminClient.AddGitHubProvider(CTX, &admin.AddGitHubProviderRequest{
Name: name,
ClientId: "clientId",
ClientSecret: "clientSecret",
Scopes: []string{"scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: false,
IsCreationAllowed: false,
IsAutoCreation: false,
IsAutoUpdate: false,
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
},
})
require.NoError(t, err)
idpRepo := repository.IDProviderRepository(pool)
var github *domain.IDPGithub
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Second*5)
assert.EventuallyWithT(t, func(t *assert.CollectT) {
github, err = idpRepo.GetGithub(CTX, idpRepo.IDCondition(addGithub.Id), instanceID, nil)
require.NoError(t, err)
assert.Equal(t, addGithub.Id, github.ID)
}, retryDuration, tick)
name = "new_" + name
// change github
beforeCreate := time.Now()
_, err = AdminClient.UpdateGitHubProvider(CTX, &admin.UpdateGitHubProviderRequest{
Id: addGithub.Id,
Name: name,
ClientId: "new_clientId",
ClientSecret: "new_clientSecret",
Scopes: []string{"new_scope"},
ProviderOptions: &idp_grpc.Options{
IsLinkingAllowed: true,
IsCreationAllowed: true,
IsAutoCreation: true,
IsAutoUpdate: true,
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
},
})
afterCreate := time.Now()
require.NoError(t, err)
// check values for azure
retryDuration, tick = integration.WaitForAndTickWithMaxDuration(CTX, time.Second*5)
assert.EventuallyWithT(t, func(t *assert.CollectT) {
updateGithub, err := idpRepo.GetGithub(CTX, idpRepo.IDCondition(addGithub.Id), instanceID, nil)
require.NoError(t, err)
// event instance.idp.github.changed
// idp
assert.Equal(t, addGithub.Id, updateGithub.ID)
assert.Equal(t, name, updateGithub.Name)
assert.Equal(t, "new_clientId", updateGithub.ClientID)
assert.NotEqual(t, github.ClientSecret, updateGithub.ClientSecret)
assert.Equal(t, domain.IDPTypeGithub.String(), updateGithub.Type)
assert.Equal(t, []string{"new_scope"}, updateGithub.Scopes)
assert.Equal(t, true, updateGithub.AllowLinking)
assert.Equal(t, true, updateGithub.AllowCreation)
assert.Equal(t, true, updateGithub.AllowAutoUpdate)
assert.Equal(t, domain.IDPAutoLinkingOptionUserName.String(), updateGithub.AllowAutoLinking)
assert.WithinRange(t, updateGithub.UpdatedAt, beforeCreate, afterCreate)
}, retryDuration, tick)
})
}

View File

@@ -229,6 +229,28 @@ func (i *idProvider) GetGoogle(ctx context.Context, id domain.IDPIdentifierCondi
return idpGoogle, nil
}
func (i *idProvider) GetGithub(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string) (*domain.IDPGithub, error) {
idpGithub := &domain.IDPGithub{}
var err error
idpGithub.IdentityProvider, err = i.Get(ctx, id, instnaceID, orgID)
if err != nil {
return nil, err
}
if idpGithub.Type != domain.IDPTypeGithub.String() {
// TODO
return nil, errors.New("WRONG TYPE")
}
err = json.Unmarshal([]byte(*idpGithub.Payload), idpGithub)
if err != nil {
return nil, err
}
return idpGithub, nil
}
// -------------------------------------------------------------
// columns
// -------------------------------------------------------------