github.com/google/go-github/v74@v74.0.0/github/secret_scanning_test.go (about) 1 // Copyright 2022 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "encoding/json" 11 "fmt" 12 "net/http" 13 "testing" 14 "time" 15 16 "github.com/google/go-cmp/cmp" 17 ) 18 19 func TestSecretScanningService_ListAlertsForEnterprise(t *testing.T) { 20 t.Parallel() 21 client, mux, _ := setup(t) 22 23 mux.HandleFunc("/enterprises/e/secret-scanning/alerts", func(w http.ResponseWriter, r *http.Request) { 24 testMethod(t, r, "GET") 25 testFormValues(t, r, values{"state": "open", "secret_type": "mailchimp_api_key", "sort": "updated", "direction": "asc"}) 26 27 fmt.Fprint(w, `[{ 28 "number": 1, 29 "created_at": "1996-06-20T00:00:00Z", 30 "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", 31 "html_url": "https://github.com/o/r/security/secret-scanning/1", 32 "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", 33 "state": "open", 34 "resolution": null, 35 "resolved_at": null, 36 "resolved_by": null, 37 "secret_type": "mailchimp_api_key", 38 "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2", 39 "repository": { 40 "id": 1, 41 "name": "n", 42 "url": "url" 43 } 44 }]`) 45 }) 46 47 ctx := context.Background() 48 opts := &SecretScanningAlertListOptions{State: "open", SecretType: "mailchimp_api_key", Direction: "asc", Sort: "updated"} 49 50 alerts, _, err := client.SecretScanning.ListAlertsForEnterprise(ctx, "e", opts) 51 if err != nil { 52 t.Errorf("SecretScanning.ListAlertsForEnterprise returned error: %v", err) 53 } 54 55 date := Timestamp{time.Date(1996, time.June, 20, 00, 00, 00, 0, time.UTC)} 56 want := []*SecretScanningAlert{ 57 { 58 Number: Ptr(1), 59 CreatedAt: &date, 60 URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), 61 HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), 62 LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), 63 State: Ptr("open"), 64 Resolution: nil, 65 ResolvedAt: nil, 66 ResolvedBy: nil, 67 SecretType: Ptr("mailchimp_api_key"), 68 Secret: Ptr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), 69 Repository: &Repository{ 70 ID: Ptr(int64(1)), 71 URL: Ptr("url"), 72 Name: Ptr("n"), 73 }, 74 }, 75 } 76 77 if !cmp.Equal(alerts, want) { 78 t.Errorf("SecretScanning.ListAlertsForEnterprise returned %+v, want %+v", alerts, want) 79 } 80 81 const methodName = "ListAlertsForEnterprise" 82 83 testBadOptions(t, methodName, func() (err error) { 84 _, _, err = client.SecretScanning.ListAlertsForEnterprise(ctx, "\n", opts) 85 return err 86 }) 87 88 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 89 _, resp, err := client.SecretScanning.ListAlertsForEnterprise(ctx, "e", opts) 90 return resp, err 91 }) 92 } 93 94 func TestSecretScanningService_ListAlertsForOrg(t *testing.T) { 95 t.Parallel() 96 client, mux, _ := setup(t) 97 98 mux.HandleFunc("/orgs/o/secret-scanning/alerts", func(w http.ResponseWriter, r *http.Request) { 99 testMethod(t, r, "GET") 100 testFormValues(t, r, values{"state": "open", "secret_type": "mailchimp_api_key", "sort": "updated", "direction": "asc"}) 101 102 fmt.Fprint(w, `[{ 103 "number": 1, 104 "created_at": "1996-06-20T00:00:00Z", 105 "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", 106 "html_url": "https://github.com/o/r/security/secret-scanning/1", 107 "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", 108 "state": "open", 109 "resolution": null, 110 "resolved_at": null, 111 "resolved_by": null, 112 "secret_type": "mailchimp_api_key", 113 "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2" 114 }]`) 115 }) 116 117 ctx := context.Background() 118 opts := &SecretScanningAlertListOptions{State: "open", SecretType: "mailchimp_api_key", Direction: "asc", Sort: "updated"} 119 120 alerts, _, err := client.SecretScanning.ListAlertsForOrg(ctx, "o", opts) 121 if err != nil { 122 t.Errorf("SecretScanning.ListAlertsForOrg returned error: %v", err) 123 } 124 125 date := Timestamp{time.Date(1996, time.June, 20, 00, 00, 00, 0, time.UTC)} 126 want := []*SecretScanningAlert{ 127 { 128 Number: Ptr(1), 129 CreatedAt: &date, 130 URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), 131 HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), 132 LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), 133 State: Ptr("open"), 134 Resolution: nil, 135 ResolvedAt: nil, 136 ResolvedBy: nil, 137 SecretType: Ptr("mailchimp_api_key"), 138 Secret: Ptr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), 139 }, 140 } 141 142 if !cmp.Equal(alerts, want) { 143 t.Errorf("SecretScanning.ListAlertsForOrg returned %+v, want %+v", alerts, want) 144 } 145 146 const methodName = "ListAlertsForOrg" 147 148 testBadOptions(t, methodName, func() (err error) { 149 _, _, err = client.SecretScanning.ListAlertsForOrg(ctx, "\n", opts) 150 return err 151 }) 152 153 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 154 _, resp, err := client.SecretScanning.ListAlertsForOrg(ctx, "o", opts) 155 return resp, err 156 }) 157 } 158 159 func TestSecretScanningService_ListAlertsForOrgListOptions(t *testing.T) { 160 t.Parallel() 161 client, mux, _ := setup(t) 162 163 mux.HandleFunc("/orgs/o/secret-scanning/alerts", func(w http.ResponseWriter, r *http.Request) { 164 testMethod(t, r, "GET") 165 testFormValues(t, r, values{"state": "open", "secret_type": "mailchimp_api_key", "per_page": "1", "page": "1", "sort": "updated", "direction": "asc"}) 166 167 fmt.Fprint(w, `[{ 168 "number": 1, 169 "created_at": "1996-06-20T00:00:00Z", 170 "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", 171 "html_url": "https://github.com/o/r/security/secret-scanning/1", 172 "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", 173 "state": "open", 174 "resolution": null, 175 "resolved_at": null, 176 "resolved_by": null, 177 "secret_type": "mailchimp_api_key", 178 "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2" 179 }]`) 180 }) 181 182 ctx := context.Background() 183 184 // Testing pagination by index 185 opts := &SecretScanningAlertListOptions{State: "open", SecretType: "mailchimp_api_key", ListOptions: ListOptions{Page: 1, PerPage: 1}, Direction: "asc", Sort: "updated"} 186 187 alerts, _, err := client.SecretScanning.ListAlertsForOrg(ctx, "o", opts) 188 if err != nil { 189 t.Errorf("SecretScanning.ListAlertsForOrg returned error: %v", err) 190 } 191 192 date := Timestamp{time.Date(1996, time.June, 20, 00, 00, 00, 0, time.UTC)} 193 want := []*SecretScanningAlert{ 194 { 195 Number: Ptr(1), 196 CreatedAt: &date, 197 URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), 198 HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), 199 LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), 200 State: Ptr("open"), 201 Resolution: nil, 202 ResolvedAt: nil, 203 ResolvedBy: nil, 204 SecretType: Ptr("mailchimp_api_key"), 205 Secret: Ptr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), 206 }, 207 } 208 209 if !cmp.Equal(alerts, want) { 210 t.Errorf("SecretScanning.ListAlertsForOrg returned %+v, want %+v", alerts, want) 211 } 212 213 const methodName = "ListAlertsForOrg" 214 215 testBadOptions(t, methodName, func() (err error) { 216 _, _, err = client.SecretScanning.ListAlertsForOrg(ctx, "\n", opts) 217 return err 218 }) 219 220 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 221 _, resp, err := client.SecretScanning.ListAlertsForOrg(ctx, "o", opts) 222 return resp, err 223 }) 224 } 225 226 func TestSecretScanningService_ListAlertsForRepo(t *testing.T) { 227 t.Parallel() 228 client, mux, _ := setup(t) 229 230 mux.HandleFunc("/repos/o/r/secret-scanning/alerts", func(w http.ResponseWriter, r *http.Request) { 231 testMethod(t, r, "GET") 232 testFormValues(t, r, values{"state": "open", "secret_type": "mailchimp_api_key", "sort": "updated", "direction": "asc"}) 233 234 fmt.Fprint(w, `[{ 235 "number": 1, 236 "created_at": "1996-06-20T00:00:00Z", 237 "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", 238 "html_url": "https://github.com/o/r/security/secret-scanning/1", 239 "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", 240 "state": "open", 241 "resolution": null, 242 "resolved_at": null, 243 "resolved_by": null, 244 "secret_type": "mailchimp_api_key", 245 "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2" 246 }]`) 247 }) 248 249 ctx := context.Background() 250 opts := &SecretScanningAlertListOptions{State: "open", SecretType: "mailchimp_api_key", Direction: "asc", Sort: "updated"} 251 252 alerts, _, err := client.SecretScanning.ListAlertsForRepo(ctx, "o", "r", opts) 253 if err != nil { 254 t.Errorf("SecretScanning.ListAlertsForRepo returned error: %v", err) 255 } 256 257 date := Timestamp{time.Date(1996, time.June, 20, 00, 00, 00, 0, time.UTC)} 258 want := []*SecretScanningAlert{ 259 { 260 Number: Ptr(1), 261 CreatedAt: &date, 262 URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), 263 HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), 264 LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), 265 State: Ptr("open"), 266 Resolution: nil, 267 ResolvedAt: nil, 268 ResolvedBy: nil, 269 SecretType: Ptr("mailchimp_api_key"), 270 Secret: Ptr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), 271 }, 272 } 273 274 if !cmp.Equal(alerts, want) { 275 t.Errorf("SecretScanning.ListAlertsForRepo returned %+v, want %+v", alerts, want) 276 } 277 278 const methodName = "ListAlertsForRepo" 279 280 testBadOptions(t, methodName, func() (err error) { 281 _, _, err = client.SecretScanning.ListAlertsForRepo(ctx, "\n", "\n", opts) 282 return err 283 }) 284 285 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 286 _, resp, err := client.SecretScanning.ListAlertsForRepo(ctx, "o", "r", opts) 287 return resp, err 288 }) 289 } 290 291 func TestSecretScanningService_GetAlert(t *testing.T) { 292 t.Parallel() 293 client, mux, _ := setup(t) 294 295 mux.HandleFunc("/repos/o/r/secret-scanning/alerts/1", func(w http.ResponseWriter, r *http.Request) { 296 testMethod(t, r, "GET") 297 298 fmt.Fprint(w, `{ 299 "number": 1, 300 "created_at": "1996-06-20T00:00:00Z", 301 "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", 302 "html_url": "https://github.com/o/r/security/secret-scanning/1", 303 "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", 304 "state": "open", 305 "resolution": null, 306 "resolved_at": null, 307 "resolved_by": null, 308 "secret_type": "mailchimp_api_key", 309 "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2" 310 }`) 311 }) 312 313 ctx := context.Background() 314 315 alert, _, err := client.SecretScanning.GetAlert(ctx, "o", "r", 1) 316 if err != nil { 317 t.Errorf("SecretScanning.GetAlert returned error: %v", err) 318 } 319 320 date := Timestamp{time.Date(1996, time.June, 20, 00, 00, 00, 0, time.UTC)} 321 want := &SecretScanningAlert{ 322 Number: Ptr(1), 323 CreatedAt: &date, 324 URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), 325 HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), 326 LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), 327 State: Ptr("open"), 328 Resolution: nil, 329 ResolvedAt: nil, 330 ResolvedBy: nil, 331 SecretType: Ptr("mailchimp_api_key"), 332 Secret: Ptr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), 333 } 334 335 if !cmp.Equal(alert, want) { 336 t.Errorf("SecretScanning.GetAlert returned %+v, want %+v", alert, want) 337 } 338 339 const methodName = "GetAlert" 340 341 testBadOptions(t, methodName, func() (err error) { 342 _, _, err = client.SecretScanning.GetAlert(ctx, "\n", "\n", 0) 343 return err 344 }) 345 346 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 347 _, resp, err := client.SecretScanning.GetAlert(ctx, "o", "r", 1) 348 return resp, err 349 }) 350 } 351 352 func TestSecretScanningService_UpdateAlert(t *testing.T) { 353 t.Parallel() 354 client, mux, _ := setup(t) 355 356 mux.HandleFunc("/repos/o/r/secret-scanning/alerts/1", func(w http.ResponseWriter, r *http.Request) { 357 testMethod(t, r, "PATCH") 358 359 v := new(SecretScanningAlertUpdateOptions) 360 assertNilError(t, json.NewDecoder(r.Body).Decode(v)) 361 362 want := &SecretScanningAlertUpdateOptions{State: "resolved", Resolution: Ptr("used_in_tests")} 363 364 if !cmp.Equal(v, want) { 365 t.Errorf("Request body = %+v, want %+v", v, want) 366 } 367 368 fmt.Fprint(w, `{ 369 "number": 1, 370 "created_at": "1996-06-20T00:00:00Z", 371 "url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1", 372 "html_url": "https://github.com/o/r/security/secret-scanning/1", 373 "locations_url": "https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations", 374 "state": "resolved", 375 "resolution": "used_in_tests", 376 "resolution_comment": "resolution comment", 377 "resolved_at": "1996-06-20T00:00:00Z", 378 "resolved_by": null, 379 "secret_type": "mailchimp_api_key", 380 "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2" 381 }`) 382 }) 383 384 ctx := context.Background() 385 opts := &SecretScanningAlertUpdateOptions{State: "resolved", Resolution: Ptr("used_in_tests")} 386 387 alert, _, err := client.SecretScanning.UpdateAlert(ctx, "o", "r", 1, opts) 388 if err != nil { 389 t.Errorf("SecretScanning.UpdateAlert returned error: %v", err) 390 } 391 392 date := Timestamp{time.Date(1996, time.June, 20, 00, 00, 00, 0, time.UTC)} 393 want := &SecretScanningAlert{ 394 Number: Ptr(1), 395 CreatedAt: &date, 396 URL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1"), 397 HTMLURL: Ptr("https://github.com/o/r/security/secret-scanning/1"), 398 LocationsURL: Ptr("https://api.github.com/repos/o/r/secret-scanning/alerts/1/locations"), 399 State: Ptr("resolved"), 400 Resolution: Ptr("used_in_tests"), 401 ResolutionComment: Ptr("resolution comment"), 402 ResolvedAt: &date, 403 ResolvedBy: nil, 404 SecretType: Ptr("mailchimp_api_key"), 405 Secret: Ptr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2"), 406 } 407 408 if !cmp.Equal(alert, want) { 409 t.Errorf("SecretScanning.UpdateAlert returned %+v, want %+v", alert, want) 410 } 411 412 const methodName = "UpdateAlert" 413 414 testBadOptions(t, methodName, func() (err error) { 415 _, _, err = client.SecretScanning.UpdateAlert(ctx, "\n", "\n", 1, opts) 416 return err 417 }) 418 419 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 420 _, resp, err := client.SecretScanning.UpdateAlert(ctx, "o", "r", 1, opts) 421 return resp, err 422 }) 423 } 424 425 func TestSecretScanningService_ListLocationsForAlert(t *testing.T) { 426 t.Parallel() 427 client, mux, _ := setup(t) 428 429 mux.HandleFunc("/repos/o/r/secret-scanning/alerts/1/locations", func(w http.ResponseWriter, r *http.Request) { 430 testMethod(t, r, "GET") 431 testFormValues(t, r, values{"page": "1", "per_page": "100"}) 432 433 fmt.Fprint(w, `[{ 434 "type": "commit", 435 "details": { 436 "path": "/example/secrets.txt", 437 "start_line": 1, 438 "end_line": 1, 439 "start_column": 1, 440 "end_column": 64, 441 "blob_sha": "af5626b4a114abcb82d63db7c8082c3c4756e51b", 442 "blob_url": "https://api.github.com/repos/o/r/git/blobs/af5626b4a114abcb82d63db7c8082c3c4756e51b", 443 "commit_sha": "f14d7debf9775f957cf4f1e8176da0786431f72b", 444 "commit_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b" 445 } 446 }]`) 447 }) 448 449 ctx := context.Background() 450 opts := &ListOptions{Page: 1, PerPage: 100} 451 452 locations, _, err := client.SecretScanning.ListLocationsForAlert(ctx, "o", "r", 1, opts) 453 if err != nil { 454 t.Errorf("SecretScanning.ListLocationsForAlert returned error: %v", err) 455 } 456 457 want := []*SecretScanningAlertLocation{ 458 { 459 Type: Ptr("commit"), 460 Details: &SecretScanningAlertLocationDetails{ 461 Path: Ptr("/example/secrets.txt"), 462 Startline: Ptr(1), 463 EndLine: Ptr(1), 464 StartColumn: Ptr(1), 465 EndColumn: Ptr(64), 466 BlobSHA: Ptr("af5626b4a114abcb82d63db7c8082c3c4756e51b"), 467 BlobURL: Ptr("https://api.github.com/repos/o/r/git/blobs/af5626b4a114abcb82d63db7c8082c3c4756e51b"), 468 CommitSHA: Ptr("f14d7debf9775f957cf4f1e8176da0786431f72b"), 469 CommitURL: Ptr("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"), 470 }, 471 }, 472 } 473 474 if !cmp.Equal(locations, want) { 475 t.Errorf("SecretScanning.ListLocationsForAlert returned %+v, want %+v", locations, want) 476 } 477 478 const methodName = "ListLocationsForAlert" 479 480 testBadOptions(t, methodName, func() (err error) { 481 _, _, err = client.SecretScanning.ListLocationsForAlert(ctx, "\n", "\n", 1, opts) 482 return err 483 }) 484 485 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 486 _, resp, err := client.SecretScanning.ListLocationsForAlert(ctx, "o", "r", 1, opts) 487 return resp, err 488 }) 489 } 490 491 func TestSecretScanningAlert_Marshal(t *testing.T) { 492 t.Parallel() 493 testJSONMarshal(t, &SecretScanningAlert{}, `{}`) 494 495 u := &SecretScanningAlert{ 496 Number: Ptr(1), 497 CreatedAt: &Timestamp{referenceTime}, 498 URL: Ptr("https://api.github.com/teams/2/discussions/3/comments"), 499 HTMLURL: Ptr("https://api.github.com/teams/2/discussions/3/comments"), 500 LocationsURL: Ptr("https://api.github.com/teams/2/discussions/3/comments"), 501 State: Ptr("test_state"), 502 Resolution: Ptr("test_resolution"), 503 ResolvedAt: &Timestamp{referenceTime}, 504 ResolvedBy: &User{ 505 Login: Ptr("test"), 506 ID: Ptr(int64(10)), 507 NodeID: Ptr("A123"), 508 AvatarURL: Ptr("https://api.github.com/teams/2/discussions/3/comments"), 509 }, 510 SecretType: Ptr("test"), 511 Secret: Ptr("test"), 512 } 513 514 want := `{ 515 "number": 1, 516 "created_at": ` + referenceTimeStr + `, 517 "url": "https://api.github.com/teams/2/discussions/3/comments", 518 "html_url": "https://api.github.com/teams/2/discussions/3/comments", 519 "locations_url": "https://api.github.com/teams/2/discussions/3/comments", 520 "state": "test_state", 521 "resolution": "test_resolution", 522 "resolved_at": ` + referenceTimeStr + `, 523 "resolved_by": { 524 "login": "test", 525 "id": 10, 526 "node_id": "A123", 527 "avatar_url": "https://api.github.com/teams/2/discussions/3/comments" 528 }, 529 "secret_type": "test", 530 "secret": "test" 531 }` 532 533 testJSONMarshal(t, u, want) 534 } 535 536 func TestSecretScanningAlertLocation_Marshal(t *testing.T) { 537 t.Parallel() 538 testJSONMarshal(t, &SecretScanningAlertLocation{}, `{}`) 539 540 u := &SecretScanningAlertLocation{ 541 Type: Ptr("test"), 542 Details: &SecretScanningAlertLocationDetails{ 543 Path: Ptr("test_path"), 544 Startline: Ptr(10), 545 EndLine: Ptr(20), 546 StartColumn: Ptr(30), 547 EndColumn: Ptr(40), 548 BlobSHA: Ptr("test_sha"), 549 BlobURL: Ptr("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"), 550 CommitSHA: Ptr("test_sha"), 551 CommitURL: Ptr("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"), 552 }, 553 } 554 555 want := `{ 556 "type": "test", 557 "details": { 558 "path": "test_path", 559 "start_line": 10, 560 "end_line": 20, 561 "start_column": 30, 562 "end_column": 40, 563 "blob_sha": "test_sha", 564 "blob_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b", 565 "commit_sha": "test_sha", 566 "commit_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b" 567 } 568 }` 569 570 testJSONMarshal(t, u, want) 571 } 572 573 func TestSecretScanningAlertLocationDetails_Marshal(t *testing.T) { 574 t.Parallel() 575 testJSONMarshal(t, &SecretScanningAlertLocationDetails{}, `{}`) 576 577 u := &SecretScanningAlertLocationDetails{ 578 Path: Ptr("test_path"), 579 Startline: Ptr(10), 580 EndLine: Ptr(20), 581 StartColumn: Ptr(30), 582 EndColumn: Ptr(40), 583 BlobSHA: Ptr("test_sha"), 584 BlobURL: Ptr("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"), 585 CommitSHA: Ptr("test_sha"), 586 CommitURL: Ptr("https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b"), 587 } 588 589 want := `{ 590 "path": "test_path", 591 "start_line": 10, 592 "end_line": 20, 593 "start_column": 30, 594 "end_column": 40, 595 "blob_sha": "test_sha", 596 "blob_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b", 597 "commit_sha": "test_sha", 598 "commit_url": "https://api.github.com/repos/o/r/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b" 599 }` 600 601 testJSONMarshal(t, u, want) 602 } 603 604 func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) { 605 t.Parallel() 606 testJSONMarshal(t, &SecretScanningAlertUpdateOptions{}, `{}`) 607 608 u := &SecretScanningAlertUpdateOptions{ 609 State: "open", 610 Resolution: Ptr("false_positive"), 611 } 612 613 want := `{ 614 "state": "open", 615 "resolution": "false_positive" 616 }` 617 618 testJSONMarshal(t, u, want) 619 }