@@ -16,17 +16,17 @@ func TestRecordArtifactChecksum(t *testing.T) {
1616 if err != nil {
1717 t .Fatal (err )
1818 }
19-
19+
2020 ctx := & buildContext {
2121 InFlightChecksums : true ,
2222 artifactChecksums : make (map [string ]string ),
2323 }
24-
24+
2525 err = ctx .recordArtifactChecksum (testArtifact )
2626 if err != nil {
2727 t .Errorf ("recordArtifactChecksum failed: %v" , err )
2828 }
29-
29+
3030 if len (ctx .artifactChecksums ) != 1 {
3131 t .Errorf ("Expected 1 checksum, got %d" , len (ctx .artifactChecksums ))
3232 }
@@ -39,30 +39,30 @@ func TestVerifyArtifactChecksum(t *testing.T) {
3939 if err != nil {
4040 t .Fatal (err )
4141 }
42-
42+
4343 ctx := & buildContext {
4444 InFlightChecksums : true ,
4545 artifactChecksums : make (map [string ]string ),
4646 }
47-
47+
4848 // Record initial checksum
4949 err = ctx .recordArtifactChecksum (testArtifact )
5050 if err != nil {
5151 t .Fatal (err )
5252 }
53-
53+
5454 // Verify unmodified file passes
5555 err = ctx .verifyArtifactChecksum (testArtifact )
5656 if err != nil {
5757 t .Errorf ("Verification should pass for unmodified file: %v" , err )
5858 }
59-
59+
6060 // Modify file to simulate TOCTU attack
6161 err = os .WriteFile (testArtifact , []byte ("tampered content" ), 0644 )
6262 if err != nil {
6363 t .Fatal (err )
6464 }
65-
65+
6666 // Verify modified file fails with TOCTU message
6767 err = ctx .verifyArtifactChecksum (testArtifact )
6868 if err == nil {
@@ -78,13 +78,13 @@ func TestInFlightChecksumsDisabled(t *testing.T) {
7878 InFlightChecksums : false ,
7979 artifactChecksums : nil ,
8080 }
81-
81+
8282 // Both operations should be no-op
8383 err := ctx .recordArtifactChecksum ("nonexistent" )
8484 if err != nil {
8585 t .Errorf ("Disabled checksumming should be no-op: %v" , err )
8686 }
87-
87+
8888 err = ctx .verifyArtifactChecksum ("nonexistent" )
8989 if err != nil {
9090 t .Errorf ("Disabled checksumming should be no-op: %v" , err )
@@ -93,44 +93,44 @@ func TestInFlightChecksumsDisabled(t *testing.T) {
9393
9494func TestVerifyAllArtifactChecksums (t * testing.T ) {
9595 tmpDir := t .TempDir ()
96-
96+
9797 // Create multiple test artifacts
9898 artifacts := []string {
9999 filepath .Join (tmpDir , "pkg1.tar.gz" ),
100100 filepath .Join (tmpDir , "pkg2.tar.gz" ),
101101 }
102-
102+
103103 ctx := & buildContext {
104104 InFlightChecksums : true ,
105105 artifactChecksums : make (map [string ]string ),
106106 }
107-
107+
108108 // Record checksums for all artifacts
109109 for i , artifact := range artifacts {
110110 content := fmt .Sprintf ("package %d content" , i )
111111 err := os .WriteFile (artifact , []byte (content ), 0644 )
112112 if err != nil {
113113 t .Fatal (err )
114114 }
115-
115+
116116 err = ctx .recordArtifactChecksum (artifact )
117117 if err != nil {
118118 t .Fatal (err )
119119 }
120120 }
121-
121+
122122 // Verify all pass initially
123123 err := verifyAllArtifactChecksums (ctx )
124124 if err != nil {
125125 t .Errorf ("All checksums should verify: %v" , err )
126126 }
127-
127+
128128 // Tamper with one artifact
129129 err = os .WriteFile (artifacts [0 ], []byte ("tampered!" ), 0644 )
130130 if err != nil {
131131 t .Fatal (err )
132132 }
133-
133+
134134 // Verification should fail
135135 err = verifyAllArtifactChecksums (ctx )
136136 if err == nil {
@@ -139,4 +139,4 @@ func TestVerifyAllArtifactChecksums(t *testing.T) {
139139 if ! strings .Contains (err .Error (), "checksum verification failures" ) {
140140 t .Errorf ("Expected verification failure message, got: %v" , err )
141141 }
142- }
142+ }
0 commit comments