-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add support for Security Advisories Request CVE endpoint #2857
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
216952f
Add support for Security Advisories Request CVE endpoint
be0x74a 1cad152
Address PR review comments
be0x74a 3b2eaf5
Merge branch 'master' into security_advisories_cve
be0x74a 2ffd446
Merge remote-tracking branch 'origin/security_advisories_cve' into se…
be0x74a 2353a17
Address PR review comments
be0x74a 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
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
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,37 @@ | ||
| // Copyright 2023 The go-github AUTHORS. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| ) | ||
|
|
||
| type SecurityAdvisoriesService service | ||
|
|
||
| // RequestCVE requests a Common Vulnerabilities and Exposures (CVE) for a repository security advisory. | ||
| // The ghsaID is the GitHub Security Advisory identifier of the advisory. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/security-advisories/repository-advisories#request-a-cve-for-a-repository-security-advisory | ||
| func (s *SecurityAdvisoriesService) RequestCVE(ctx context.Context, owner, repo, ghsaID string) (*Response, error) { | ||
| url := fmt.Sprintf("repos/%v/%v/security-advisories/%v/cve", owner, repo, ghsaID) | ||
|
|
||
| req, err := s.client.NewRequest("POST", url, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| resp, err := s.client.Do(ctx, req, nil) | ||
| if err != nil { | ||
| if _, ok := err.(*AcceptedError); ok { | ||
| return resp, nil | ||
| } | ||
|
|
||
| return resp, err | ||
| } | ||
|
|
||
| return resp, nil | ||
| } |
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,52 @@ | ||
| // Copyright 2023 The go-github AUTHORS. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestSecurityAdvisoriesService_RequestCVE(t *testing.T) { | ||
| client, mux, _, teardown := setup() | ||
| defer teardown() | ||
|
|
||
| mux.HandleFunc("/repos/o/r/security-advisories/ghsa_id_ok/cve", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "POST") | ||
| w.WriteHeader(http.StatusOK) | ||
| }) | ||
|
|
||
| mux.HandleFunc("/repos/o/r/security-advisories/ghsa_id_accepted/cve", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "POST") | ||
| w.WriteHeader(http.StatusAccepted) | ||
| }) | ||
|
|
||
| ctx := context.Background() | ||
| _, err := client.SecurityAdvisories.RequestCVE(ctx, "o", "r", "ghsa_id_ok") | ||
| if err != nil { | ||
| t.Errorf("SecurityAdvisoriesService.RequestCVE returned error: %v", err) | ||
| } | ||
|
|
||
| _, err = client.SecurityAdvisories.RequestCVE(ctx, "o", "r", "ghsa_id_accepted") | ||
| if err != nil { | ||
| t.Errorf("SecurityAdvisoriesService.RequestCVE returned error: %v", err) | ||
| } | ||
|
|
||
| const methodName = "RequestCVE" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, err = client.SecurityAdvisories.RequestCVE(ctx, "\n", "\n", "\n") | ||
| return err | ||
| }) | ||
|
|
||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| resp, err := client.SecurityAdvisories.RequestCVE(ctx, "o", "r", "ghsa_id") | ||
| if err == nil { | ||
| t.Errorf("testNewRequestAndDoFailure %v should have return err", methodName) | ||
| } | ||
| return resp, err | ||
| }) | ||
| } | ||
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.