@@ -11,7 +11,6 @@ import (
1111func TestSignature_JSONSerialization (t * testing.T ) {
1212 timestamp := time .Date (2024 , 1 , 15 , 10 , 30 , 45 , 123456789 , time .UTC )
1313 createdAt := time .Date (2024 , 1 , 15 , 10 , 30 , 46 , 0 , time .UTC )
14- userName := "Test User"
1514 referer := "https://github.com/user/repo"
1615 prevHash := "abcd1234efgh5678"
1716
@@ -20,7 +19,7 @@ func TestSignature_JSONSerialization(t *testing.T) {
2019 DocID : "test-doc-123" ,
2120 UserSub : "google-oauth2|123456789" ,
2221 UserEmail : "test@example.com" ,
23- UserName : & userName ,
22+ UserName : "Test User" ,
2423 SignedAtUTC : timestamp ,
2524 PayloadHash : "SGVsbG8gV29ybGQ=" ,
2625 Signature : "c2lnbmF0dXJlLWRhdGE=" ,
@@ -53,11 +52,8 @@ func TestSignature_JSONSerialization(t *testing.T) {
5352 if unmarshaled .UserEmail != signature .UserEmail {
5453 t .Errorf ("UserEmail mismatch: got %v, expected %v" , unmarshaled .UserEmail , signature .UserEmail )
5554 }
56- if (unmarshaled .UserName == nil ) != (signature .UserName == nil ) {
57- t .Errorf ("UserName nil mismatch: got %v, expected %v" , unmarshaled .UserName == nil , signature .UserName == nil )
58- }
59- if unmarshaled .UserName != nil && signature .UserName != nil && * unmarshaled .UserName != * signature .UserName {
60- t .Errorf ("UserName mismatch: got %v, expected %v" , * unmarshaled .UserName , * signature .UserName )
55+ if unmarshaled .UserName != signature .UserName {
56+ t .Errorf ("UserName mismatch: got %v, expected %v" , unmarshaled .UserName , signature .UserName )
6157 }
6258 if ! unmarshaled .SignedAtUTC .Equal (signature .SignedAtUTC ) {
6359 t .Errorf ("SignedAtUTC mismatch: got %v, expected %v" , unmarshaled .SignedAtUTC , signature .SignedAtUTC )
@@ -97,7 +93,7 @@ func TestSignature_JSONSerializationWithNilFields(t *testing.T) {
9793 DocID : "minimal-doc" ,
9894 UserSub : "github|987654321" ,
9995 UserEmail : "minimal@example.com" ,
100- UserName : nil ,
96+ UserName : "" ,
10197 SignedAtUTC : timestamp ,
10298 PayloadHash : "bWluaW1hbA==" ,
10399 Signature : "bWluaW1hbC1zaWc=" ,
@@ -129,8 +125,8 @@ func TestSignature_JSONSerializationWithNilFields(t *testing.T) {
129125 t .Fatalf ("Failed to unmarshal signature: %v" , err )
130126 }
131127
132- if unmarshaled .UserName != nil {
133- t .Errorf ("UserName should be nil , got %v" , unmarshaled .UserName )
128+ if unmarshaled .UserName != "" {
129+ t .Errorf ("UserName should be empty string , got %v" , unmarshaled .UserName )
134130 }
135131 if unmarshaled .Referer != nil {
136132 t .Errorf ("Referer should be nil, got %v" , unmarshaled .Referer )
@@ -242,15 +238,14 @@ func TestSignature_GetServiceInfo(t *testing.T) {
242238func TestSignature_ComputeRecordHash (t * testing.T ) {
243239 timestamp := time .Date (2024 , 1 , 15 , 10 , 30 , 45 , 123456789 , time .UTC )
244240 createdAt := time .Date (2024 , 1 , 15 , 10 , 30 , 46 , 0 , time .UTC )
245- userName := "Test User"
246241 referer := "https://github.com/user/repo"
247242
248243 signature := & Signature {
249244 ID : 123 ,
250245 DocID : "test-doc-123" ,
251246 UserSub : "google-oauth2|123456789" ,
252247 UserEmail : "test@example.com" ,
253- UserName : & userName ,
248+ UserName : "Test User" ,
254249 SignedAtUTC : timestamp ,
255250 PayloadHash : "SGVsbG8gV29ybGQ=" ,
256251 Signature : "c2lnbmF0dXJlLWRhdGE=" ,
@@ -282,13 +277,13 @@ func TestSignature_ComputeRecordHash(t *testing.T) {
282277 }
283278 signature .ID = originalID
284279
285- signature .UserName = nil
286- hashWithNilName := signature .ComputeRecordHash ()
287- if hashWithNilName == hash1 {
288- t .Error ("Hash should change when UserName becomes nil " )
280+ signature .UserName = ""
281+ hashWithEmptyName := signature .ComputeRecordHash ()
282+ if hashWithEmptyName == hash1 {
283+ t .Error ("Hash should change when UserName becomes empty " )
289284 }
290285
291- signature .UserName = & userName
286+ signature .UserName = "Test User"
292287 signature .Referer = nil
293288 hashWithNilReferer := signature .ComputeRecordHash ()
294289 if hashWithNilReferer == hash1 {
@@ -300,15 +295,14 @@ func TestSignature_ComputeRecordHashDeterministic(t *testing.T) {
300295 // Test that the same signature data produces the same hash
301296 timestamp := time .Date (2024 , 1 , 15 , 10 , 30 , 45 , 123456789 , time .UTC )
302297 createdAt := time .Date (2024 , 1 , 15 , 10 , 30 , 46 , 0 , time .UTC )
303- userName := "Test User"
304298 referer := "https://github.com/user/repo"
305299
306300 sig1 := & Signature {
307301 ID : 123 ,
308302 DocID : "test-doc-123" ,
309303 UserSub : "google-oauth2|123456789" ,
310304 UserEmail : "test@example.com" ,
311- UserName : & userName ,
305+ UserName : "Test User" ,
312306 SignedAtUTC : timestamp ,
313307 PayloadHash : "SGVsbG8gV29ybGQ=" ,
314308 Signature : "c2lnbmF0dXJlLWRhdGE=" ,
@@ -322,7 +316,7 @@ func TestSignature_ComputeRecordHashDeterministic(t *testing.T) {
322316 DocID : "test-doc-123" ,
323317 UserSub : "google-oauth2|123456789" ,
324318 UserEmail : "test@example.com" ,
325- UserName : & userName ,
319+ UserName : "Test User" ,
326320 SignedAtUTC : timestamp ,
327321 PayloadHash : "SGVsbG8gV29ybGQ=" ,
328322 Signature : "c2lnbmF0dXJlLWRhdGE=" ,
0 commit comments