Skip to content

Conversation

@sophia-chen-ttd
Copy link
Contributor

@sophia-chen-ttd sophia-chen-ttd commented May 9, 2025

  • populates previous salt field when salt is rotated
  • removes previous salt if salt is over 90 days old

Unit tests:

  • rotateSaltsPopulatePreviousSaltOnRotation()
    - when a salt is rotated, populate the previous salt field with the current salt

  • rotateSaltsPreservePreviousSaltsLessThan90DaysOld()
    - salts that are under 90 days old and are not being rotated will keep their previous salt

  • rotateSaltsRemovePreviousSaltsOver90DaysOld()
    - salts that are equal to or over 90 days old and are not being rotated will have their previous salts removed

assertEquals("salt1", result.getSnapshot().getAllRotatingSalts()[0].previousSalt());
assertEquals("salt2", result.getSnapshot().getAllRotatingSalts()[1].previousSalt());
assertEquals("salt3", result.getSnapshot().getAllRotatingSalts()[2].previousSalt());
assertEquals(7, Arrays.stream(result.getSnapshot().getAllRotatingSalts()).filter(s -> s.previousSalt() == null).count());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, this is the "preserve old value of previousSalt for not rotated salts"? I suggest we move that into a separate test and use a mix of salts with previousSalt null and previousSalt not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is just checking that we haven't populated the previous salt for salts that haven't rotated, not necessarily preserving the old value.


final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, minAges, 0.5, targetDate);
assertTrue(result.hasSnapshot());
assertEquals(2, Arrays.stream(result.getSnapshot().getAllRotatingSalts()).filter(s -> "lessThan90DaysOld".equals(s.previousSalt())).count());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to just assert on what's the previous salts are at each position like you did in the previous test? This will be a bit more complicated to figure out if this test fails.

final long over90Days = daysEarlier(100).toEpochMilli();
final RotatingSaltProvider.SaltSnapshot lastSnapshot = SnapshotBuilder.start()
.withEntries(
new SaltEntry(1, "1", lessThan90Days, "currentSalt", null, "lessThan90DaysOld", null, null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why double up all the test cases?

@sophia-chen-ttd sophia-chen-ttd merged commit f279482 into main May 13, 2025
4 checks passed
@sophia-chen-ttd sophia-chen-ttd deleted the sch-UID2-5339-salt-rotation-previous-salt branch May 13, 2025 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants