Skip to content

Commit d3b3af3

Browse files
committed
CET-19215 add secret scanning
1 parent 3041720 commit d3b3af3

File tree

7 files changed

+376
-102
lines changed

7 files changed

+376
-102
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.kohsuke</groupId>
44
<artifactId>cortexapps-github-api</artifactId>
5-
<version>1.326</version>
5+
<version>1.327</version>
66
<name>GitHub API for Java</name>
77
<url>https://github-api.kohsuke.org/</url>
88
<description>GitHub API for Java</description>

src/main/java/org/kohsuke/github/GHSecretScanningAlert.java

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ public class GHSecretScanningAlert extends GHObject {
2222
private String resolution;
2323
private String resolved_at;
2424
private GHUser resolved_by;
25+
private String secret_name;
2526
private String secret_type;
26-
private Secret secret;
27-
private String push_protection_bypassed;
27+
private String secret_type_display_name;
28+
private String secret;
29+
30+
private Boolean push_protection_bypassed;
2831
private GHUser push_protection_bypassed_by;
2932
private String push_protection_bypassed_at;
3033

@@ -105,11 +108,29 @@ public String getSecretType() {
105108
}
106109

107110
/**
108-
* Secret that was detected
111+
* Display name for tyype of secret that was detected
112+
*
113+
* @return the secret type display name
114+
*/
115+
public String getSecretTypeDisplayName() {
116+
return secret_type_display_name;
117+
}
118+
119+
/**
120+
* Secret name that was detected
121+
*
122+
* @return the secret name
123+
*/
124+
public String getSecretName() {
125+
return secret_name;
126+
}
127+
128+
/**
129+
* Secret value that was detected
109130
*
110-
* @return the secret
131+
* @return the secret value
111132
*/
112-
public Secret getSecret() {
133+
public String getSecret() {
113134
return secret;
114135
}
115136

@@ -118,8 +139,8 @@ public Secret getSecret() {
118139
*
119140
* @return true if push protection was bypassed, false otherwise
120141
*/
121-
public boolean isPushProtectionBypassed() {
122-
return push_protection_bypassed != null && !push_protection_bypassed.isEmpty();
142+
public Boolean isPushProtectionBypassed() {
143+
return push_protection_bypassed;
123144
}
124145

125146
/**
@@ -146,40 +167,4 @@ public URL getHtmlUrl() throws IOException {
146167
return GitHubClient.parseURL(html_url);
147168
}
148169

149-
/**
150-
* Secret details
151-
*/
152-
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
153-
public static class Secret {
154-
private String name;
155-
private String type;
156-
private String value;
157-
158-
/**
159-
* Name of the secret
160-
*
161-
* @return the name
162-
*/
163-
public String getName() {
164-
return name;
165-
}
166-
167-
/**
168-
* Type of the secret
169-
*
170-
* @return the type
171-
*/
172-
public String getType() {
173-
return type;
174-
}
175-
176-
/**
177-
* Value of the secret
178-
*
179-
* @return the value
180-
*/
181-
public String getValue() {
182-
return value;
183-
}
184-
}
185170
}
Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.kohsuke.github;
22

3-
import org.junit.Assume;
43
import org.junit.Before;
54
import org.junit.Test;
65

7-
import java.io.IOException;
86
import java.util.List;
97

108
import static org.hamcrest.Matchers.*;
@@ -28,11 +26,11 @@ public class GHSecretScanningAlertTest extends AbstractGitHubWireMockTest {
2826
*/
2927
@Before
3028
public void setUp() throws Exception {
31-
repo = gitHub.getRepository("cortextests" + "/" + "test-code-scanning");
29+
repo = gitHub.getRepository("cortextests" + "/" + "secret-scanning");
3230
}
3331

3432
/**
35-
* Test list code scanning alert payload
33+
* Test list secret scanning alert payload
3634
*/
3735
@Test
3836
public void testListSecretScanningAlerts() {
@@ -42,62 +40,27 @@ public void testListSecretScanningAlerts() {
4240
List<GHSecretScanningAlert> alerts = repo.listSecretScanningAlerts()._iterator(2).nextPage();
4341

4442
// Assert
45-
assertThat(alerts.size(), equalTo(2)); // This assertion is based on manual setup done on repo to
46-
// guarantee there are atleast 2 issues
43+
assertThat(alerts.size(), equalTo(2));
4744

48-
// GHCodeScanningAlert alert = codeQlAlerts.get(0);
49-
//
50-
// // Verify the code scanning tool details
51-
// assertThat(alert.getTool(), not((Object) null));
52-
// GHCodeScanningAlert.Tool tool = alert.getTool();
53-
// assertThat(tool.getName(), is("CodeQL"));
54-
// assertThat(tool.getVersion(), not((Object) null));
55-
//
56-
// // Verify that fields of the code scanning rule are non-null
57-
// assertThat(alert.getRule(), not((Object) null));
58-
// GHCodeScanningAlert.Rule rule = alert.getRule();
59-
// assertThat(rule.getId(), not((Object) null));
60-
// assertThat(rule.getName(), not((Object) null));
61-
// assertThat(rule.getSeverity(), not((Object) null));
62-
// assertThat(rule.getSecuritySeverityLevel(), not((Object) null));
63-
//
64-
// // Act - Search by filtering on alert status
65-
// List<GHCodeScanningAlert> openAlerts = repo.listCodeScanningAlerts(GHCodeScanningAlertState.OPEN)
66-
// ._iterator(2)
67-
// .nextPage(); // This assertion is based on manual setup done on repo to
68-
// // guarantee there are atleast 2 issues
69-
//
70-
// // Assert
71-
// assertThat(openAlerts.size(), equalTo(2));
72-
// GHCodeScanningAlert openAlert = openAlerts.get(0);
73-
// assertThat(openAlert.getState(), is(GHCodeScanningAlertState.OPEN));
74-
}
75-
76-
/**
77-
* Test get code scanning alert payload
78-
*
79-
* @throws IOException
80-
* Signals that an I/O exception has occurred.
81-
*/
82-
@Test
83-
public void testGetCodeScanningAlert() throws IOException {
84-
// Arrange
85-
List<GHCodeScanningAlert> dismissedAlerts = repo.listCodeScanningAlerts(GHCodeScanningAlertState.DISMISSED)
86-
._iterator(1)
87-
.nextPage();
88-
Assume.assumeThat(dismissedAlerts.size(), greaterThanOrEqualTo(1));
89-
GHCodeScanningAlert dismissedAlert = dismissedAlerts.get(0);
90-
long idOfDismissed = dismissedAlert.getId();
45+
GHSecretScanningAlert alert1 = alerts.get(0);
46+
assertThat(alert1.getNumber(), equalTo(2L));
47+
assertThat(alert1.getState(), equalTo(GHSecretScanningAlertState.OPEN));
48+
assertThat(alert1.getSecretType(), equalTo("npm_access_token"));
49+
assertThat(alert1.getSecret(), equalTo("secret1"));
50+
assertThat(alert1.isPushProtectionBypassed(), equalTo(false));
51+
assertThat(alert1.getResolvedBy(), nullValue());
52+
assertThat(alert1.getResolvedAt(), nullValue());
9153

92-
// Act
93-
GHCodeScanningAlert result = repo.getCodeScanningAlert(idOfDismissed);
94-
95-
// Assert
96-
assertThat(result, not((Object) null));
97-
assertThat(result.getId(), equalTo(idOfDismissed));
98-
assertThat(result.getDismissedReason(), equalTo(dismissedAlert.getDismissedReason()));
99-
assertThat(result.getDismissedAt(), equalTo(dismissedAlert.getDismissedAt()));
100-
assertThat(result.getDismissedBy().login, equalTo(dismissedAlert.getDismissedBy().login));
54+
GHSecretScanningAlert alert2 = alerts.get(1);
55+
assertThat(alert2.getNumber(), equalTo(1L));
56+
assertThat(alert2.getState(), equalTo(GHSecretScanningAlertState.OPEN));
57+
assertThat(alert2.getSecretType(), equalTo("stripe_test_secret_key"));
58+
assertThat(alert2.getSecret(), equalTo("secret2"));
59+
assertThat(alert2.isPushProtectionBypassed(), equalTo(true));
60+
assertThat(alert2.getPushProtectionBypassedBy().getLogin(), equalTo("lukbla"));
61+
assertThat(alert2.getPushProtectionBypassedAt(), equalTo(GitHubClient.parseDate("2025-05-05T15:32:05Z")));
62+
assertThat(alert2.getResolvedBy(), nullValue());
63+
assertThat(alert2.getResolvedAt(), nullValue());
10164
}
10265

10366
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
"id": 978177282,
3+
"node_id": "R_kgDOOk3NAg",
4+
"name": "secret-scanning",
5+
"full_name": "cortextests/secret-scanning",
6+
"private": false,
7+
"owner": {
8+
"login": "cortextests",
9+
"id": 87100841,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjg3MTAwODQx",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/87100841?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/cortextests",
14+
"html_url": "https://github.com/cortextests",
15+
"followers_url": "https://api.github.com/users/cortextests/followers",
16+
"following_url": "https://api.github.com/users/cortextests/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/cortextests/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/cortextests/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/cortextests/subscriptions",
20+
"organizations_url": "https://api.github.com/users/cortextests/orgs",
21+
"repos_url": "https://api.github.com/users/cortextests/repos",
22+
"events_url": "https://api.github.com/users/cortextests/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/cortextests/received_events",
24+
"type": "Organization",
25+
"user_view_type": "public",
26+
"site_admin": false
27+
},
28+
"html_url": "https://github.com/cortextests/secret-scanning",
29+
"description": null,
30+
"fork": false,
31+
"url": "https://api.github.com/repos/cortextests/secret-scanning",
32+
"forks_url": "https://api.github.com/repos/cortextests/secret-scanning/forks",
33+
"keys_url": "https://api.github.com/repos/cortextests/secret-scanning/keys{/key_id}",
34+
"collaborators_url": "https://api.github.com/repos/cortextests/secret-scanning/collaborators{/collaborator}",
35+
"teams_url": "https://api.github.com/repos/cortextests/secret-scanning/teams",
36+
"hooks_url": "https://api.github.com/repos/cortextests/secret-scanning/hooks",
37+
"issue_events_url": "https://api.github.com/repos/cortextests/secret-scanning/issues/events{/number}",
38+
"events_url": "https://api.github.com/repos/cortextests/secret-scanning/events",
39+
"assignees_url": "https://api.github.com/repos/cortextests/secret-scanning/assignees{/user}",
40+
"branches_url": "https://api.github.com/repos/cortextests/secret-scanning/branches{/branch}",
41+
"tags_url": "https://api.github.com/repos/cortextests/secret-scanning/tags",
42+
"blobs_url": "https://api.github.com/repos/cortextests/secret-scanning/git/blobs{/sha}",
43+
"git_tags_url": "https://api.github.com/repos/cortextests/secret-scanning/git/tags{/sha}",
44+
"git_refs_url": "https://api.github.com/repos/cortextests/secret-scanning/git/refs{/sha}",
45+
"trees_url": "https://api.github.com/repos/cortextests/secret-scanning/git/trees{/sha}",
46+
"statuses_url": "https://api.github.com/repos/cortextests/secret-scanning/statuses/{sha}",
47+
"languages_url": "https://api.github.com/repos/cortextests/secret-scanning/languages",
48+
"stargazers_url": "https://api.github.com/repos/cortextests/secret-scanning/stargazers",
49+
"contributors_url": "https://api.github.com/repos/cortextests/secret-scanning/contributors",
50+
"subscribers_url": "https://api.github.com/repos/cortextests/secret-scanning/subscribers",
51+
"subscription_url": "https://api.github.com/repos/cortextests/secret-scanning/subscription",
52+
"commits_url": "https://api.github.com/repos/cortextests/secret-scanning/commits{/sha}",
53+
"git_commits_url": "https://api.github.com/repos/cortextests/secret-scanning/git/commits{/sha}",
54+
"comments_url": "https://api.github.com/repos/cortextests/secret-scanning/comments{/number}",
55+
"issue_comment_url": "https://api.github.com/repos/cortextests/secret-scanning/issues/comments{/number}",
56+
"contents_url": "https://api.github.com/repos/cortextests/secret-scanning/contents/{+path}",
57+
"compare_url": "https://api.github.com/repos/cortextests/secret-scanning/compare/{base}...{head}",
58+
"merges_url": "https://api.github.com/repos/cortextests/secret-scanning/merges",
59+
"archive_url": "https://api.github.com/repos/cortextests/secret-scanning/{archive_format}{/ref}",
60+
"downloads_url": "https://api.github.com/repos/cortextests/secret-scanning/downloads",
61+
"issues_url": "https://api.github.com/repos/cortextests/secret-scanning/issues{/number}",
62+
"pulls_url": "https://api.github.com/repos/cortextests/secret-scanning/pulls{/number}",
63+
"milestones_url": "https://api.github.com/repos/cortextests/secret-scanning/milestones{/number}",
64+
"notifications_url": "https://api.github.com/repos/cortextests/secret-scanning/notifications{?since,all,participating}",
65+
"labels_url": "https://api.github.com/repos/cortextests/secret-scanning/labels{/name}",
66+
"releases_url": "https://api.github.com/repos/cortextests/secret-scanning/releases{/id}",
67+
"deployments_url": "https://api.github.com/repos/cortextests/secret-scanning/deployments",
68+
"created_at": "2025-05-05T15:30:32Z",
69+
"updated_at": "2025-05-05T15:32:18Z",
70+
"pushed_at": "2025-05-05T15:32:15Z",
71+
"git_url": "git://github.com/cortextests/secret-scanning.git",
72+
"ssh_url": "git@github.com:cortextests/secret-scanning.git",
73+
"clone_url": "https://github.com/cortextests/secret-scanning.git",
74+
"svn_url": "https://github.com/cortextests/secret-scanning",
75+
"homepage": null,
76+
"size": 1,
77+
"stargazers_count": 0,
78+
"watchers_count": 0,
79+
"language": null,
80+
"has_issues": true,
81+
"has_projects": true,
82+
"has_downloads": true,
83+
"has_wiki": true,
84+
"has_pages": false,
85+
"has_discussions": false,
86+
"forks_count": 0,
87+
"mirror_url": null,
88+
"archived": false,
89+
"disabled": false,
90+
"open_issues_count": 0,
91+
"license": null,
92+
"allow_forking": true,
93+
"is_template": false,
94+
"web_commit_signoff_required": false,
95+
"topics": [],
96+
"visibility": "public",
97+
"forks": 0,
98+
"open_issues": 0,
99+
"watchers": 0,
100+
"default_branch": "main",
101+
"permissions": {
102+
"admin": true,
103+
"maintain": true,
104+
"push": true,
105+
"triage": true,
106+
"pull": true
107+
},
108+
"temp_clone_token": "",
109+
"allow_squash_merge": true,
110+
"allow_merge_commit": true,
111+
"allow_rebase_merge": true,
112+
"allow_auto_merge": false,
113+
"delete_branch_on_merge": false,
114+
"allow_update_branch": false,
115+
"use_squash_pr_title_as_default": false,
116+
"squash_merge_commit_message": "COMMIT_MESSAGES",
117+
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
118+
"merge_commit_message": "PR_TITLE",
119+
"merge_commit_title": "MERGE_MESSAGE",
120+
"custom_properties": {},
121+
"organization": {
122+
"login": "cortextests",
123+
"id": 87100841,
124+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjg3MTAwODQx",
125+
"avatar_url": "https://avatars.githubusercontent.com/u/87100841?v=4",
126+
"gravatar_id": "",
127+
"url": "https://api.github.com/users/cortextests",
128+
"html_url": "https://github.com/cortextests",
129+
"followers_url": "https://api.github.com/users/cortextests/followers",
130+
"following_url": "https://api.github.com/users/cortextests/following{/other_user}",
131+
"gists_url": "https://api.github.com/users/cortextests/gists{/gist_id}",
132+
"starred_url": "https://api.github.com/users/cortextests/starred{/owner}{/repo}",
133+
"subscriptions_url": "https://api.github.com/users/cortextests/subscriptions",
134+
"organizations_url": "https://api.github.com/users/cortextests/orgs",
135+
"repos_url": "https://api.github.com/users/cortextests/repos",
136+
"events_url": "https://api.github.com/users/cortextests/events{/privacy}",
137+
"received_events_url": "https://api.github.com/users/cortextests/received_events",
138+
"type": "Organization",
139+
"user_view_type": "public",
140+
"site_admin": false
141+
},
142+
"security_and_analysis": {
143+
"secret_scanning": {
144+
"status": "enabled"
145+
},
146+
"secret_scanning_push_protection": {
147+
"status": "disabled"
148+
},
149+
"dependabot_security_updates": {
150+
"status": "disabled"
151+
},
152+
"secret_scanning_non_provider_patterns": {
153+
"status": "disabled"
154+
},
155+
"secret_scanning_validity_checks": {
156+
"status": "disabled"
157+
}
158+
},
159+
"network_count": 0,
160+
"subscribers_count": 4
161+
}

0 commit comments

Comments
 (0)