-
Notifications
You must be signed in to change notification settings - Fork 37
chore(ers): add BDD cukes for multi-strategy ERS (Claims + LDAP) #3767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jrschumacher
merged 8 commits into
opentdf:main
from
khvirtru:test/multi-strategy-ers-cukes
Jul 24, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3263744
test(ers): add BDD cukes for multi-strategy ERS (Claims + LDAP)
khvirtru 032476b
docs(ers): add multi-strategy ERS testing section to BDD README
khvirtru 5ad690d
fix(test): clean up LDAP container on setup failure
khvirtru fbcb6b2
chore(ers): fix golangci-lint issues in steps_ldap.go
khvirtru 91dd337
chore(docs): fix markdown lint in multi-strategy ERS README section
khvirtru 562e3c2
chore(ers): inline ERS config in feature file with DocString steps
khvirtru 57a9d4a
chore: retrigger CI
khvirtru 68e2413
chore: retrigger CI
khvirtru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| package cukes | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "text/template" | ||
|
|
||
| "github.com/cucumber/godog" | ||
| "gopkg.in/yaml.v2" | ||
| ) | ||
|
|
||
| const ersConfigKey = "ers_inline_config" | ||
|
|
||
| type ERSInlineConfig struct { | ||
| Mode string | ||
| FailureStrategy string | ||
| Providers map[string]ERSProviderConfig | ||
| Strategies []ERSMappingStrategyConfig | ||
| } | ||
|
|
||
| type ERSProviderConfig struct { | ||
| Type string | ||
| AutoWireLDAP bool | ||
| } | ||
|
|
||
| type ERSMappingStrategyConfig struct { | ||
| Name string | ||
| Provider string | ||
| RawYAML string | ||
| } | ||
|
|
||
| type ERSStepDefinitions struct { | ||
| PlatformCukesContext *PlatformTestSuiteContext | ||
| PlatformSteps *LocalPlatformStepDefinitions | ||
| } | ||
|
|
||
| func getERSConfig(sc *PlatformScenarioContext) (*ERSInlineConfig, error) { | ||
| obj := sc.GetObject(ersConfigKey) | ||
| if obj == nil { | ||
| return nil, errors.New("no ERS configuration found; use 'an ERS configuration' step first") | ||
| } | ||
| cfg, ok := obj.(*ERSInlineConfig) | ||
| if !ok { | ||
| return nil, errors.New("invalid ERS configuration object") | ||
| } | ||
| return cfg, nil | ||
| } | ||
|
|
||
| func (s *ERSStepDefinitions) anERSConfiguration(ctx context.Context, mode string, failureStrategy string) (context.Context, error) { | ||
| scenarioContext := GetPlatformScenarioContext(ctx) | ||
| cfg := &ERSInlineConfig{ | ||
| Mode: mode, | ||
| FailureStrategy: failureStrategy, | ||
| Providers: make(map[string]ERSProviderConfig), | ||
| } | ||
| scenarioContext.RecordObject(ersConfigKey, cfg) | ||
| return ctx, nil | ||
| } | ||
|
|
||
| func (s *ERSStepDefinitions) anERSProvider(ctx context.Context, name string, providerType string) (context.Context, error) { | ||
| scenarioContext := GetPlatformScenarioContext(ctx) | ||
| cfg, err := getERSConfig(scenarioContext) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| cfg.Providers[name] = ERSProviderConfig{Type: providerType} | ||
| return ctx, nil | ||
| } | ||
|
|
||
| func (s *ERSStepDefinitions) anERSProviderConnectedToLDAP(ctx context.Context, name string, providerType string) (context.Context, error) { | ||
| scenarioContext := GetPlatformScenarioContext(ctx) | ||
| cfg, err := getERSConfig(scenarioContext) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| cfg.Providers[name] = ERSProviderConfig{ | ||
| Type: providerType, | ||
| AutoWireLDAP: true, | ||
| } | ||
| return ctx, nil | ||
| } | ||
|
|
||
| func (s *ERSStepDefinitions) anERSMappingStrategy(ctx context.Context, name string, provider string, doc *godog.DocString) (context.Context, error) { | ||
| scenarioContext := GetPlatformScenarioContext(ctx) | ||
| cfg, err := getERSConfig(scenarioContext) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| cfg.Strategies = append(cfg.Strategies, ERSMappingStrategyConfig{ | ||
| Name: name, | ||
| Provider: provider, | ||
| RawYAML: doc.Content, | ||
| }) | ||
| return ctx, nil | ||
| } | ||
|
|
||
| func (s *ERSStepDefinitions) aLocalPlatformWithInlineERSConfiguration(ctx context.Context) (context.Context, error) { | ||
| scenarioContext := GetPlatformScenarioContext(ctx) | ||
| cfg, err := getERSConfig(scenarioContext) | ||
| if err != nil { | ||
| return ctx, err | ||
| } | ||
| kt := template.Must(template.New("kc").Parse(keycloakBaseTemplate)) | ||
| return s.PlatformSteps.commonLocalPlatform(ctx, &platformStartOptions{ | ||
| kcProvisionPath: kt, | ||
| ersConfig: cfg, | ||
| }) | ||
| } | ||
|
|
||
| func buildEntityResolutionConfig(cfg *ERSInlineConfig, hostname string, ldapPort int) (map[string]interface{}, error) { | ||
| providers := map[string]interface{}{} | ||
| for name, p := range cfg.Providers { | ||
| provider := map[string]interface{}{ | ||
| "type": p.Type, | ||
| } | ||
| if p.AutoWireLDAP { | ||
| provider["connection"] = map[string]interface{}{ | ||
| "host": hostname, | ||
| "port": ldapPort, | ||
| "use_tls": false, | ||
| "bind_dn": "cn=admin,dc=opentdf,dc=test", | ||
| "bind_password": "admin123", | ||
| } | ||
| } else { | ||
| provider["connection"] = map[string]interface{}{} | ||
| } | ||
| providers[name] = provider | ||
| } | ||
|
|
||
| var strategies []interface{} | ||
| for _, s := range cfg.Strategies { | ||
| var rawStrategy map[interface{}]interface{} | ||
| if err := yaml.Unmarshal([]byte(s.RawYAML), &rawStrategy); err != nil { | ||
| return nil, fmt.Errorf("failed to parse mapping strategy %q YAML: %w", s.Name, err) | ||
| } | ||
| strategy := map[string]interface{}{ | ||
| "name": s.Name, | ||
| "provider": s.Provider, | ||
| } | ||
| for k, v := range rawStrategy { | ||
| strategy[fmt.Sprintf("%v", k)] = v | ||
| } | ||
| strategies = append(strategies, strategy) | ||
| } | ||
|
|
||
| return map[string]interface{}{ | ||
| "mode": cfg.Mode, | ||
| "failure_strategy": cfg.FailureStrategy, | ||
| "providers": providers, | ||
| "mapping_strategies": strategies, | ||
| }, nil | ||
| } | ||
|
|
||
| func RegisterERSStepDefinitions(ctx *godog.ScenarioContext, x *PlatformTestSuiteContext) { | ||
| steps := &ERSStepDefinitions{ | ||
| PlatformCukesContext: x, | ||
| PlatformSteps: &LocalPlatformStepDefinitions{PlatformCukesContext: x}, | ||
| } | ||
| ctx.Step(`^an ERS configuration with mode "([^"]*)" and failure strategy "([^"]*)"$`, steps.anERSConfiguration) | ||
| ctx.Step(`^an ERS provider "([^"]*)" of type "([^"]*)"$`, steps.anERSProvider) | ||
| ctx.Step(`^an ERS provider "([^"]*)" of type "([^"]*)" connected to the LDAP directory$`, steps.anERSProviderConnectedToLDAP) | ||
| ctx.Step(`^an ERS mapping strategy "([^"]*)" using provider "([^"]*)"$`, steps.anERSMappingStrategy) | ||
| ctx.Step(`^a local platform with inline ERS configuration$`, steps.aLocalPlatformWithInlineERSConfiguration) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.