From 5f16c07ef93258987cee7485e57876242bd4d7ab Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 3 Aug 2024 17:10:53 -0600 Subject: [PATCH] Remove mock object test replaced in earlier commit (#1623) * 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 --- src/test/java/hudson/plugins/git/GitStatusTest.java | 13 ------------- src/test/java/hudson/plugins/git/GitStepTest.java | 12 ++++++------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/test/java/hudson/plugins/git/GitStatusTest.java b/src/test/java/hudson/plugins/git/GitStatusTest.java index cad26f9c47..ce0a133867 100644 --- a/src/test/java/hudson/plugins/git/GitStatusTest.java +++ b/src/test/java/hudson/plugins/git/GitStatusTest.java @@ -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 { diff --git a/src/test/java/hudson/plugins/git/GitStepTest.java b/src/test/java/hudson/plugins/git/GitStepTest.java index e4838e5575..a5322cdfde 100644 --- a/src/test/java/hudson/plugins/git/GitStepTest.java +++ b/src/test/java/hudson/plugins/git/GitStepTest.java @@ -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 @@ -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")); } }