-
Notifications
You must be signed in to change notification settings - Fork 0
fix(reliability): fail closed on artifact ledger persistence errors #357
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eea4685
test(artifact): fail closed on ledger persistence errors
seonghobae 5b28d5a
fix(reliability): persist artifact ledger before publication
seonghobae 2fc0eb6
test(reliability): reject artifact token authority rebinding
seonghobae d8ddbe3
fix(reliability): reject artifact token authority rebinding
seonghobae e1afe0f
test(reliability): reject persisted token authority rebinding
seonghobae 823b994
test(reliability): preserve ledger mismatch coverage without rebinding
seonghobae bc91ee4
fix(reliability): fail closed on duplicate ledger replay
seonghobae 316cf5f
refactor(reliability): keep ledger replay fix minimal
seonghobae 58fa7c4
test(reliability): require durable append before authority publication
seonghobae 548f29f
fix(reliability): force durable ledger append before publication
seonghobae 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
105 changes: 105 additions & 0 deletions
105
src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkLedgerAuthorityRebindingTest.java
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,105 @@ | ||
| package com.clearfolio.viewer.artifact; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardOpenOption; | ||
| import java.time.Instant; | ||
| import java.util.Base64; | ||
| import java.util.UUID; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| class ArtifactLinkLedgerAuthorityRebindingTest { | ||
|
|
||
| @TempDir | ||
| private Path tempDir; | ||
|
|
||
| @Test | ||
| void duplicateTokenIdentifierCannotRebindIssuedAuthority() { | ||
| Path ledgerPath = tempDir.resolve("artifact-ledger.log"); | ||
| ArtifactLinkLedger ledger = new ArtifactLinkLedger(ledgerPath); | ||
| ArtifactLinkRecord original = issuedRecord("token-1", "tenant-a", UUID.randomUUID()); | ||
| ArtifactLinkRecord conflicting = issuedRecord("token-1", "tenant-b", UUID.randomUUID()); | ||
|
|
||
| ledger.recordIssued(original); | ||
|
|
||
| IllegalStateException error = assertThrows( | ||
| IllegalStateException.class, | ||
| () -> ledger.recordIssued(conflicting) | ||
| ); | ||
|
|
||
| assertEquals("artifact token identifier is already issued", error.getMessage()); | ||
| assertEquals(original, ledger.findByTokenId("token-1").orElseThrow()); | ||
| assertEquals(original, new ArtifactLinkLedger(ledgerPath).findByTokenId("token-1").orElseThrow()); | ||
| } | ||
|
|
||
| @Test | ||
| void replayRejectsPersistedTokenAuthorityRebinding() throws Exception { | ||
| Path ledgerPath = tempDir.resolve("artifact-ledger-replay.log"); | ||
| ArtifactLinkRecord original = issuedRecord("token-1", "tenant-a", UUID.randomUUID()); | ||
| ArtifactLinkRecord conflicting = issuedRecord("token-1", "tenant-b", UUID.randomUUID()); | ||
| ArtifactLinkLedger ledger = new ArtifactLinkLedger(ledgerPath); | ||
| ledger.recordIssued(original); | ||
| Files.writeString( | ||
| ledgerPath, | ||
| issuedLine(conflicting) + System.lineSeparator(), | ||
| StandardCharsets.UTF_8, | ||
| StandardOpenOption.APPEND | ||
| ); | ||
|
|
||
| IllegalStateException error = assertThrows( | ||
| IllegalStateException.class, | ||
| () -> new ArtifactLinkLedger(ledgerPath) | ||
| ); | ||
|
|
||
| assertEquals("artifact link ledger contains an invalid line", error.getMessage()); | ||
| } | ||
|
|
||
| private static ArtifactLinkRecord issuedRecord(String tokenId, String tenantId, UUID docId) { | ||
| return new ArtifactLinkRecord( | ||
| tokenId, | ||
| tenantId, | ||
| "subject-a", | ||
| docId, | ||
| ArtifactLinkService.ARTIFACT_READ_SCOPE, | ||
| "viewer-preview", | ||
| "checksum", | ||
| null, | ||
| Instant.EPOCH, | ||
| Instant.EPOCH.plusSeconds(300), | ||
| null, | ||
| null, | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| private static String issuedLine(ArtifactLinkRecord record) { | ||
| return String.join("\t", | ||
| "ISSUED", | ||
| encoded(record.tokenId()), | ||
| encoded(record.tenantId()), | ||
| encoded(record.subjectId()), | ||
| record.docId().toString(), | ||
| encoded(record.scope()), | ||
| encoded(record.purpose()), | ||
| encoded(record.artifactChecksum()), | ||
| "-", | ||
| record.issuedAt().toString(), | ||
| record.expiresAt().toString(), | ||
| "-", | ||
| "-", | ||
| "-" | ||
| ); | ||
| } | ||
|
|
||
| private static String encoded(String value) { | ||
| return Base64.getUrlEncoder() | ||
| .withoutPadding() | ||
| .encodeToString(value.getBytes(StandardCharsets.UTF_8)); | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
src/test/java/com/clearfolio/viewer/artifact/ArtifactLinkLedgerDurabilityTest.java
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,64 @@ | ||
| package com.clearfolio.viewer.artifact; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardOpenOption; | ||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| class ArtifactLinkLedgerDurabilityTest { | ||
|
|
||
| @Test | ||
| void doesNotPublishIssuedAuthorityWhenDurableAcknowledgementFails(@TempDir Path tempDir) { | ||
| Path ledgerPath = tempDir.resolve("artifact-links.ledger"); | ||
| ArtifactLinkLedger ledger = new ArtifactLinkLedger(ledgerPath, (path, line) -> { | ||
| Files.writeString( | ||
| path, | ||
| line, | ||
| StandardCharsets.UTF_8, | ||
| StandardOpenOption.CREATE, | ||
| StandardOpenOption.WRITE, | ||
| StandardOpenOption.APPEND | ||
| ); | ||
| throw new IOException("durable acknowledgement failed"); | ||
| }); | ||
| ArtifactLinkRecord record = issuedRecord(); | ||
|
|
||
| IllegalStateException failure = assertThrows( | ||
| IllegalStateException.class, | ||
| () -> ledger.recordIssued(record) | ||
| ); | ||
|
|
||
| assertEquals("artifact link ledger cannot be written", failure.getMessage()); | ||
| assertTrue(ledger.findByTokenId(record.tokenId()).isEmpty()); | ||
| assertTrue(Files.exists(ledgerPath)); | ||
| } | ||
|
|
||
| private static ArtifactLinkRecord issuedRecord() { | ||
| Instant issuedAt = Instant.parse("2026-08-11T04:00:00Z"); | ||
| return new ArtifactLinkRecord( | ||
| "token-1", | ||
| "tenant-1", | ||
| "subject-1", | ||
| UUID.fromString("00000000-0000-0000-0000-000000000357"), | ||
| "artifact:read", | ||
| "viewer-preview", | ||
| "checksum", | ||
| null, | ||
| issuedAt, | ||
| issuedAt.plusSeconds(300), | ||
| null, | ||
| null, | ||
| null | ||
| ); | ||
| } | ||
| } |
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.