-
Notifications
You must be signed in to change notification settings - Fork 0
BCH-1290: Include certificate domain name in evidence title #5
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c9a68d5
BCH-1290: Include certificate domain name in evidence title
saltpy-cs 19a382c
BCH-1290: Load bundle data.json once per eval cycle, not once per cert
saltpy-cs d2b1aa2
BCH-1290: Address PR review 13 — use GetTitle() proto getter
saltpy-cs a2283f7
BCH-1290: Simplify policyData — single map, not map-of-maps
saltpy-cs fb30406
BCH-1290: Address PR review 14 — fix data.json lookup order and add p…
saltpy-cs 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestLoadBundleRootData_OverridesWinOverBundleDefaults(t *testing.T) { | ||
| dir := t.TempDir() | ||
| bundleJSON := `{"expiry_warning_days":30,"required_certificate_tags":["Environment"]}` | ||
| if err := os.WriteFile(filepath.Join(dir, "data.json"), []byte(bundleJSON), 0644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| overrides := map[string]interface{}{ | ||
| "expiry_warning_days": float64(90), | ||
| } | ||
|
|
||
| result, err := LoadBundleRootData(dir, overrides) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| // Operator override (90) must win over bundle default (30). | ||
| if got := result["expiry_warning_days"]; got != float64(90) { | ||
| t.Errorf("expiry_warning_days: got %v, want 90", got) | ||
| } | ||
|
|
||
| // Bundle key absent from overrides must still be present. | ||
| if _, ok := result["required_certificate_tags"]; !ok { | ||
| t.Error("required_certificate_tags from bundle missing from merged result") | ||
| } | ||
| } | ||
|
|
||
| func TestLoadBundleRootData_NoBundleDataJsonReturnsOverrides(t *testing.T) { | ||
| dir := t.TempDir() // no data.json written | ||
|
|
||
| overrides := map[string]interface{}{ | ||
| "expiry_warning_days": float64(60), | ||
| } | ||
|
|
||
| result, err := LoadBundleRootData(dir, overrides) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| if got := result["expiry_warning_days"]; got != float64(60) { | ||
| t.Errorf("expiry_warning_days: got %v, want 60", got) | ||
| } | ||
| } | ||
|
|
||
| func TestLoadBundleRootData_PolicyPathDataJsonWinsOverParent(t *testing.T) { | ||
| root := t.TempDir() | ||
| parentJSON := `{"expiry_warning_days":30,"source":"parent"}` | ||
| if err := os.WriteFile(filepath.Join(root, "data.json"), []byte(parentJSON), 0644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| policiesDir := filepath.Join(root, "policies") | ||
| if err := os.Mkdir(policiesDir, 0755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| policiesJSON := `{"expiry_warning_days":60,"source":"policyPath"}` | ||
| if err := os.WriteFile(filepath.Join(policiesDir, "data.json"), []byte(policiesJSON), 0644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // When both data.json locations exist, policyPath/data.json must win. | ||
| result, err := LoadBundleRootData(policiesDir, nil) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| if got := result["source"]; got != "policyPath" { | ||
| t.Errorf("source: got %v, want policyPath", got) | ||
| } | ||
| if got := result["expiry_warning_days"]; got != float64(60) { | ||
| t.Errorf("expiry_warning_days: got %v, want 60", got) | ||
| } | ||
| } | ||
|
|
||
| func TestLoadBundleRootData_FindsDataJsonOneDirectoryUp(t *testing.T) { | ||
| root := t.TempDir() | ||
| bundleJSON := `{"expiry_warning_days":30}` | ||
| if err := os.WriteFile(filepath.Join(root, "data.json"), []byte(bundleJSON), 0644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| policiesDir := filepath.Join(root, "policies") | ||
| if err := os.Mkdir(policiesDir, 0755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // policyPath is the policies/ subdirectory; data.json is one level up. | ||
| result, err := LoadBundleRootData(policiesDir, nil) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| if got := result["expiry_warning_days"]; got != float64(30) { | ||
| t.Errorf("expiry_warning_days: got %v, want 30", got) | ||
| } | ||
| } | ||
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
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.