Skip to content
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

adv ttl mgmt: refactor window tests #22472

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions builtin/logical/database/path_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,6 @@ func TestWALsDeletedOnRoleDeletion(t *testing.T) {
}

func TestIsInsideRotationWindow(t *testing.T) {
rotationPeriodData := map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_period": "86400s",
}

for _, tc := range []struct {
name string
expected bool
Expand All @@ -920,16 +914,16 @@ func TestIsInsideRotationWindow(t *testing.T) {
{
"always returns true for rotation_period type",
true,
rotationPeriodData,
map[string]interface{}{
"rotation_period": "86400s",
},
time.Now(),
nil,
},
{
"always returns true for rotation_schedule when no rotation_window set",
true,
map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_schedule": "0 0 */2 * * *",
},
time.Now(),
Expand All @@ -939,8 +933,6 @@ func TestIsInsideRotationWindow(t *testing.T) {
"returns true for rotation_schedule when inside rotation_window",
true,
map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_schedule": "0 0 */2 * * *",
"rotation_window": "3600s",
},
Expand All @@ -954,8 +946,6 @@ func TestIsInsideRotationWindow(t *testing.T) {
"returns false for rotation_schedule when outside rotation_window",
false,
map[string]interface{}{
"username": "hashicorp",
"db_name": "mockv5",
"rotation_schedule": "0 0 */2 * * *",
"rotation_window": "3600s",
},
Expand Down Expand Up @@ -988,13 +978,14 @@ func TestIsInsideRotationWindow(t *testing.T) {
testTime = tc.timeModifier(next2)
}

tc.data["username"] = "hashicorp"
tc.data["db_name"] = "mockv5"
createRoleWithData(t, b, s, mockDB, "test-role", tc.data)
role, err := b.StaticRole(ctx, s, "test-role")
if err != nil {
t.Fatal(err)
}

// testTime := sched.Next(time.Now()).tc.timeModifier()
isInsideWindow := role.StaticAccount.IsInsideRotationWindow(testTime)
if tc.expected != isInsideWindow {
t.Fatalf("expected %t, got %t", tc.expected, isInsideWindow)
Expand Down
Loading