Skip to content

Commit

Permalink
rpc/migration: limit project in one-time migration too
Browse files Browse the repository at this point in the history
  • Loading branch information
patrislav committed Aug 23, 2024
1 parent 0c51977 commit 6251a25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rpc/migration/oidc_to_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (m *OIDCToEmail) OnRegisterSession(ctx context.Context, originalAccount *da
}

func (m *OIDCToEmail) NextBatch(ctx context.Context, projectID uint64, page data.Page) ([]string, data.Page, error) {
if !slices.Contains(m.config.Projects, projectID) {
return nil, data.Page{}, fmt.Errorf("project id does not match")
}

items := make([]string, 0, page.Limit)
for {
accounts, page, err := m.accounts.ListByProjectAndIdentity(ctx, page, projectID, proto.IdentityType_OIDC, m.config.IssuerPrefix)
Expand Down Expand Up @@ -113,6 +117,10 @@ func (m *OIDCToEmail) NextBatch(ctx context.Context, projectID uint64, page data
}

func (m *OIDCToEmail) ProcessItems(ctx context.Context, tenant *proto.TenantData, items []string) (*Result, error) {
if !slices.Contains(m.config.Projects, tenant.ProjectID) {
return nil, fmt.Errorf("project id does not match")
}

if len(items) > 100 {
return nil, fmt.Errorf("can only process 100 items at a time")
}
Expand Down
3 changes: 3 additions & 0 deletions rpc/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ func TestMigrationEmail(t *testing.T) {
issuer, tok, closeJWKS := issueAccessTokenAndRunJwksServer(t, tokBuilderFn)
defer closeJWKS()

projectID := currentProjectID.Load() + 1
svc := initRPC(t, func(cfg *config.Config) {
cfg.Migrations.Email = config.EmailMigrationConfig{
Enabled: true,
IssuerPrefix: issuer,
Projects: []uint64{projectID},
}
})
tenant, _ := newTenant(t, svc.Enclave, issuer)
Expand Down Expand Up @@ -316,6 +318,7 @@ func TestMigrationEmail(t *testing.T) {
cfg.Migrations.Email = config.EmailMigrationConfig{
Enabled: true,
IssuerPrefix: issuer,
Projects: []uint64{projectID},
}
})
tenant, _ := newTenant(t, svc.Enclave, issuer)
Expand Down

0 comments on commit 6251a25

Please sign in to comment.