Skip to content

Commit

Permalink
Remove mock object test replaced in earlier commit (jenkinsci#1623)
Browse files Browse the repository at this point in the history
* Remove mocked test replaced in earlier commit

* Match assertions to test names

When transforming the tests from mock objects to JenkinsRule, I mistakenly
placed the notifyCommit calls and the assertions in the wrong methods.
Switch them so that the assertion being performed matches the name of
the test.

* Fix comments in tests
  • Loading branch information
MarkEWaite committed Aug 3, 2024
1 parent a5e5fcd commit 5f16c07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
13 changes: 0 additions & 13 deletions src/test/java/hudson/plugins/git/GitStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,19 +591,6 @@ public void testDoNotifyCommitWithUnauthenticatedPollingAllowed() throws Excepti
Mockito.verify(trigger).run();
}

@Test
@Issue("SECURITY-284")
public void testDoNotifyCommitWithSha1AndAllowModePoll() throws Exception {
GitStatus.NOTIFY_COMMIT_ACCESS_CONTROL = "disabled-for-polling";
setupProjectWithTrigger("a", "master", false);
StaplerResponse res = mock(StaplerResponse.class);

HttpResponse httpResponse = this.gitStatus.doNotifyCommit(requestWithNoParameter, "a", "master", sha1, null);
httpResponse.generateResponse(null, res, null);

Mockito.verify(res).sendError(401, "An access token is required when using the sha1 parameter. Please refer to Git plugin documentation (https://plugins.jenkins.io/git/#plugin-content-push-notification-from-repository) for details.");
}

@Test
@Issue("SECURITY-284")
public void testDoNotifyCommitWithAllowModeSha1() throws Exception {
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/hudson/plugins/git/GitStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ public void testDoNotifyCommitWithSha1AndAllowModePollWithInvalidToken() throws
assumeTrue("Test class max time " + MAX_SECONDS_FOR_THESE_TESTS + " exceeded", isTimeAvailable());
GitStatus.NOTIFY_COMMIT_ACCESS_CONTROL = "disabled-for-polling";
createJob();
/* sha1 is ignored because no access token is provided */
/* sha1 is ignored because invalid access token is provided */
String sha1 = "4b714b66959463a98e9dfb1983db5a39a39fa6d6";
String response = sampleRepo.notifyCommit(r, null, sha1);
assertThat(response, containsString("An access token is required when using the sha1 parameter"));
String response = sampleRepo.notifyCommit(r, GitSampleRepoRule.INVALID_NOTIFY_COMMIT_TOKEN, sha1);
assertThat(response, containsString("Invalid access token"));
}

@Test
Expand All @@ -359,10 +359,10 @@ public void testDoNotifyCommitWithSha1AndAllowModePoll() throws Exception {
assumeTrue("Test class max time " + MAX_SECONDS_FOR_THESE_TESTS + " exceeded", isTimeAvailable());
GitStatus.NOTIFY_COMMIT_ACCESS_CONTROL = "disabled-for-polling";
createJob();
/* sha1 is ignored because invalid access token is provided */
/* sha1 is ignored because no access token is provided */
String sha1 = "4b714b66959463a98e9dfb1983db5a39a39fa6d6";
String response = sampleRepo.notifyCommit(r, GitSampleRepoRule.INVALID_NOTIFY_COMMIT_TOKEN, sha1);
assertThat(response, containsString("Invalid access token"));
String response = sampleRepo.notifyCommit(r, null, sha1);
assertThat(response, containsString("An access token is required when using the sha1 parameter"));
}

}

0 comments on commit 5f16c07

Please sign in to comment.