forked from XAMPPRocky/octocrab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,82 @@ | ||
[ | ||
{ | ||
"number": 2, | ||
"created_at": "2020-11-06T18:48:51Z", | ||
"url": "https://api.github.com/repos/owner/private-repo/secret-scanning/alerts/2", | ||
"html_url": "https://github.com/owner/private-repo/security/secret-scanning/2", | ||
"locations_url": "https://api.github.com/repos/owner/private-repo/secret-scanning/alerts/2/locations", | ||
"state": "resolved", | ||
"resolution": "false_positive", | ||
"resolved_at": "2020-11-07T02:47:13Z", | ||
"resolved_by": { | ||
"login": "monalisa", | ||
"id": 2, | ||
"node_id": "MDQ6VXNlcjI=", | ||
"avatar_url": "https://alambic.github.com/avatars/u/2?", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/monalisa", | ||
"html_url": "https://github.com/monalisa", | ||
"followers_url": "https://api.github.com/users/monalisa/followers", | ||
"following_url": "https://api.github.com/users/monalisa/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/monalisa/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/monalisa/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/monalisa/subscriptions", | ||
"organizations_url": "https://api.github.com/users/monalisa/orgs", | ||
"repos_url": "https://api.github.com/users/monalisa/repos", | ||
"events_url": "https://api.github.com/users/monalisa/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/monalisa/received_events", | ||
"type": "User", | ||
"site_admin": true | ||
}, | ||
"secret_type": "adafruit_io_key", | ||
"secret_type_display_name": "Adafruit IO Key", | ||
"secret": "aio_XXXXXXXXXXXXXXXXXXXXXXXXXXXX", | ||
"push_protection_bypassed_by": { | ||
"login": "monalisa", | ||
"id": 2, | ||
"node_id": "MDQ6VXNlcjI=", | ||
"avatar_url": "https://alambic.github.com/avatars/u/2?", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/monalisa", | ||
"html_url": "https://github.com/monalisa", | ||
"followers_url": "https://api.github.com/users/monalisa/followers", | ||
"following_url": "https://api.github.com/users/monalisa/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/monalisa/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/monalisa/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/monalisa/subscriptions", | ||
"organizations_url": "https://api.github.com/users/monalisa/orgs", | ||
"repos_url": "https://api.github.com/users/monalisa/repos", | ||
"events_url": "https://api.github.com/users/monalisa/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/monalisa/received_events", | ||
"type": "User", | ||
"site_admin": true | ||
}, | ||
"push_protection_bypassed": true, | ||
"push_protection_bypassed_at": "2020-11-06T21:48:51Z", | ||
"resolution_comment": "Example comment", | ||
"validity": "inactive", | ||
"publicly_leaked": false, | ||
"multi_repo": false | ||
}, | ||
{ | ||
"number": 1, | ||
"created_at": "2020-11-06T18:18:30Z", | ||
"url": "https://api.github.com/repos/owner/repo/secret-scanning/alerts/1", | ||
"html_url": "https://github.com/owner/repo/security/secret-scanning/1", | ||
"locations_url": "https://api.github.com/repos/owner/private-repo/secret-scanning/alerts/1/locations", | ||
"state": "open", | ||
"resolution": null, | ||
"resolved_at": null, | ||
"resolved_by": null, | ||
"secret_type": "mailchimp_api_key", | ||
"secret_type_display_name": "Mailchimp API Key", | ||
"secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-us2", | ||
"push_protection_bypassed_by": null, | ||
"push_protection_bypassed": false, | ||
"push_protection_bypassed_at": null, | ||
"resolution_comment": null, | ||
"validity": "unknown", | ||
"publicly_leaked": false, | ||
"multi_repo": false | ||
} | ||
] |
This file contains 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,78 @@ | ||
use wiremock::{ | ||
matchers::{method, path}, | ||
Mock, MockServer, ResponseTemplate, | ||
}; | ||
|
||
use mock_error::setup_error_handler; | ||
use octocrab::models::repos::secret_scanning_alert::SecretScanningAlert; | ||
use octocrab::Octocrab; | ||
|
||
mod mock_error; | ||
|
||
const OWNER: &str = "org"; | ||
const REPO: &str = "some-repo"; | ||
|
||
async fn setup_secrets_api(template: ResponseTemplate) -> MockServer { | ||
let mock_server = MockServer::start().await; | ||
|
||
Mock::given(method("GET")) | ||
.and(path(format!( | ||
"/repos/{owner}/{repo}/secret-scanning/alerts", | ||
owner = OWNER, | ||
repo = REPO | ||
))) | ||
.respond_with(template.clone()) | ||
.mount(&mock_server) | ||
.await; | ||
setup_error_handler( | ||
&mock_server, | ||
&format!( | ||
"GET on /repos/{owner}/{repo}/secret-scanning/alerts was not received", | ||
owner = OWNER, | ||
repo = REPO | ||
), | ||
) | ||
.await; | ||
|
||
mock_server | ||
} | ||
|
||
fn setup_octocrab(uri: &str) -> Octocrab { | ||
Octocrab::builder().base_uri(uri).unwrap().build().unwrap() | ||
} | ||
|
||
#[tokio::test] | ||
async fn check_list_200() { | ||
let s: &str = include_str!("resources/check_secrets_alerts.json"); | ||
let alert: Vec<SecretScanningAlert> = serde_json::from_str(s).unwrap(); | ||
let template = ResponseTemplate::new(200).set_body_json(&alert); | ||
let mock_server = setup_secrets_api(template).await; | ||
let client = setup_octocrab(&mock_server.uri()); | ||
|
||
let result = client | ||
.repos(OWNER.to_owned(), REPO.to_owned()) | ||
.secrets_scanning() | ||
.get_alerts() | ||
.await; | ||
|
||
assert!( | ||
result.is_ok(), | ||
"expected successful result, got error: {:?}", | ||
result | ||
); | ||
|
||
let response = result.unwrap(); | ||
let items = response.items; | ||
|
||
assert_eq!(items.len(), 2); | ||
|
||
{ | ||
let item = &items[0]; | ||
|
||
assert_eq!(2, item.number); | ||
assert_eq!( | ||
octocrab::models::repos::secret_scanning_alert::State::Open, | ||
item.state | ||
); | ||
} | ||
} |