From 0689914d4b0a78d76610fccb2eba44b2c50443a3 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 17 Sep 2024 12:44:21 -0700 Subject: [PATCH] Update AbuseLimitHandlerTest --- .../org/kohsuke/github/AbuseLimitHandler.java | 5 +- .../kohsuke/github/AbuseLimitHandlerTest.java | 114 +++++++++--------- .../mappings/2-r_h_t_fail.json | 13 +- .../mappings/3-r_h_t_fail.json | 27 +++-- .../mappings/2-r_h_t_fail.json | 13 +- .../mappings/3-r_h_t_fail.json | 27 +++-- .../mappings/2-r_h_t_fail.json | 49 ++++++++ .../mappings/3-r_h_t_fail.json | 27 +++-- 8 files changed, 160 insertions(+), 115 deletions(-) create mode 100644 src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/2-r_h_t_fail.json diff --git a/src/main/java/org/kohsuke/github/AbuseLimitHandler.java b/src/main/java/org/kohsuke/github/AbuseLimitHandler.java index 6b68be7b43..288a1542bd 100644 --- a/src/main/java/org/kohsuke/github/AbuseLimitHandler.java +++ b/src/main/java/org/kohsuke/github/AbuseLimitHandler.java @@ -108,6 +108,9 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException { } }; + // If "Retry-After" missing, wait for unambiguously over one minute per GitHub guidance + static long DEFAULT_WAIT_MILLIS = 61 * 1000; + /* * Exposed for testability. Given an http response, find the retry-after header field and parse it as either a * number or a date (the spec allows both). If no header is found, wait for a reasonably amount of time. @@ -116,7 +119,7 @@ long parseWaitTime(HttpURLConnection uc) { String v = uc.getHeaderField("Retry-After"); if (v == null) { // can't tell, wait for unambiguously over one minute per GitHub guidance - return 61 * 1000; + return DEFAULT_WAIT_MILLIS; } try { diff --git a/src/test/java/org/kohsuke/github/AbuseLimitHandlerTest.java b/src/test/java/org/kohsuke/github/AbuseLimitHandlerTest.java index 5736146c4c..526143ca5e 100644 --- a/src/test/java/org/kohsuke/github/AbuseLimitHandlerTest.java +++ b/src/test/java/org/kohsuke/github/AbuseLimitHandlerTest.java @@ -15,7 +15,6 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.core.IsInstanceOf.instanceOf; @@ -71,8 +70,7 @@ public void testHandler_Fail() throws Exception { snapshotNotAllowed(); final HttpURLConnection[] savedConnection = new HttpURLConnection[1]; - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(new AbuseLimitHandler() { + gitHub = getGitHubWithAbuseLimitHandler(new TestAbuseLimitHandler() { @Override public void onError(IOException e, HttpURLConnection uc) throws IOException { savedConnection[0] = uc; @@ -224,8 +222,7 @@ public void testHandler_HttpStatus_Fail() throws Exception { // Customized response that templates the date to keep things working snapshotNotAllowed(); - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(AbuseLimitHandler.FAIL) + gitHub = getGitHubWithAbuseLimitHandler(AbuseLimitHandler.FAIL) .build(); gitHub.getMyself(); @@ -257,8 +254,7 @@ public void testHandler_Wait() throws Exception { // Customized response that templates the date to keep things working snapshotNotAllowed(); - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(AbuseLimitHandler.WAIT) + gitHub = getGitHubWithAbuseLimitHandler(AbuseLimitHandler.WAIT) .build(); gitHub.getMyself(); @@ -279,8 +275,7 @@ public void testHandler_WaitStuck() throws Exception { // Customized response that templates the date to keep things working snapshotNotAllowed(); - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(new AbuseLimitHandler() { + gitHub = getGitHubWithAbuseLimitHandler(new TestAbuseLimitHandler() { @Override public void onError(IOException e, HttpURLConnection uc) throws IOException { } @@ -312,8 +307,7 @@ public void testHandler_Wait_Secondary_Limits() throws Exception { // Customized response that templates the date to keep things working snapshotNotAllowed(); final HttpURLConnection[] savedConnection = new HttpURLConnection[1]; - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(new AbuseLimitHandler() { + gitHub = getGitHubWithAbuseLimitHandler(new TestAbuseLimitHandler() { /** * Overriding method because the actual method will wait for one minute causing slowness in unit * tests @@ -343,25 +337,26 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException { assertThat(uc.getContentLength(), equalTo(-1)); assertThat(uc.getHeaderFields(), instanceOf(Map.class)); assertThat(uc.getHeaderFields().size(), greaterThan(25)); + + assertThat(AbuseLimitHandler.DEFAULT_WAIT_MILLIS, equalTo(61 * 1000l)); + AbuseLimitHandler.DEFAULT_WAIT_MILLIS = 3210l; + long waitTime = parseWaitTime(uc); + assertThat(waitTime, equalTo(AbuseLimitHandler.DEFAULT_WAIT_MILLIS)); + assertThat(uc.getHeaderField("Status"), equalTo("403 Forbidden")); checkErrorMessageMatches(uc, "You have exceeded a secondary rate limit. Please wait a few minutes before you try again"); - AbuseLimitHandler.FAIL.onError(e, uc); + AbuseLimitHandler.WAIT.onError(e, uc); } }) .build(); gitHub.getMyself(); assertThat(mockGitHub.getRequestCount(), equalTo(1)); - try { - getTempRepository(); - fail(); - } catch (Exception e) { - assertThat(e, instanceOf(HttpException.class)); - assertThat(e.getMessage(), equalTo("Abuse limit reached")); - } - assertThat(mockGitHub.getRequestCount(), equalTo(2)); + + getTempRepository(); + assertThat(mockGitHub.getRequestCount(), equalTo(3)); } /** @@ -388,8 +383,7 @@ public void testHandler_Wait_Secondary_Limits_Too_Many_Requests() throws Excepti // Customized response that templates the date to keep things working snapshotNotAllowed(); final HttpURLConnection[] savedConnection = new HttpURLConnection[1]; - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(new AbuseLimitHandler() { + gitHub = getGitHubWithAbuseLimitHandler(new TestAbuseLimitHandler() { /** * Overriding method because the actual method will wait for one minute causing slowness in unit * tests @@ -415,27 +409,20 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException { checkErrorMessageMatches(uc, "You have exceeded a secondary rate limit. Please wait a few minutes before you try again"); - // Because we've overridden onError to bypass the wait, we don't cover the wait calculation - // logic - // Manually invoke it to make sure it's what we intended + long waitTime = parseWaitTime(uc); - assertThat(waitTime, equalTo(42 * 1000l)); + assertThat(waitTime, equalTo(8 * 1000l)); - AbuseLimitHandler.FAIL.onError(e, uc); + AbuseLimitHandler.WAIT.onError(e, uc); } }) .build(); gitHub.getMyself(); assertThat(mockGitHub.getRequestCount(), equalTo(1)); - try { - getTempRepository(); - fail(); - } catch (Exception e) { - assertThat(e, instanceOf(HttpException.class)); - assertThat(e.getMessage(), equalTo("Abuse limit reached")); - } - assertThat(mockGitHub.getRequestCount(), equalTo(2)); + + getTempRepository(); + assertThat(mockGitHub.getRequestCount(), equalTo(3)); } /** @@ -449,8 +436,7 @@ public void testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After // Customized response that templates the date to keep things working snapshotNotAllowed(); final HttpURLConnection[] savedConnection = new HttpURLConnection[1]; - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(new AbuseLimitHandler() { + gitHub = getGitHubWithAbuseLimitHandler(new TestAbuseLimitHandler() { /** * Overriding method because the actual method will wait for one minute causing slowness in unit * tests @@ -472,28 +458,23 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException { checkErrorMessageMatches(uc, "You have exceeded a secondary rate limit. Please wait a few minutes before you try again"); - // Because we've overridden onError to bypass the wait, we don't cover the wait calculation - // logic - // Manually invoke it to make sure it's what we intended long waitTime = parseWaitTime(uc); - // The exact value here will depend on when the test is run, but it should be positive, and huge - assertThat(waitTime, greaterThan(1000 * 1000l)); + // The exact value here will depend on when the test is run + assertThat(waitTime, Matchers.lessThan(AbuseLimitHandler.DEFAULT_WAIT_MILLIS)); + assertThat(waitTime, Matchers.greaterThan(3 * 1000l)); - AbuseLimitHandler.FAIL.onError(e, uc); + + AbuseLimitHandler.WAIT.onError(e, uc); } }) .build(); + gitHub.getMyself(); assertThat(mockGitHub.getRequestCount(), equalTo(1)); - try { - getTempRepository(); - fail(); - } catch (Exception e) { - assertThat(e, instanceOf(HttpException.class)); - assertThat(e.getMessage(), equalTo("Abuse limit reached")); - } - assertThat(mockGitHub.getRequestCount(), equalTo(2)); + + getTempRepository(); + assertThat(mockGitHub.getRequestCount(), equalTo(3)); } /** @@ -507,8 +488,7 @@ public void testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After() // Customized response that templates the date to keep things working snapshotNotAllowed(); final HttpURLConnection[] savedConnection = new HttpURLConnection[1]; - gitHub = getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) - .withAbuseLimitHandler(new AbuseLimitHandler() { + gitHub = getGitHubWithAbuseLimitHandler(new TestAbuseLimitHandler() { /** * Overriding method because the actual method will wait for one minute causing slowness in unit * tests @@ -533,13 +513,12 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException { checkErrorMessageMatches(uc, "You have exceeded a secondary rate limit. Please wait a few minutes before you try again"); - // Because we've overridden onError to bypass the wait, we don't cover the wait calculation - // logic - // Manually invoke it to make sure it's what we intended - long waitTime = parseWaitTime(uc); - assertThat(waitTime, greaterThan(60000l)); - AbuseLimitHandler.FAIL.onError(e, uc); + AbuseLimitHandler.DEFAULT_WAIT_MILLIS = 3210l; + long waitTime = parseWaitTime(uc); + assertThat(waitTime, equalTo(AbuseLimitHandler.DEFAULT_WAIT_MILLIS)); + + AbuseLimitHandler.WAIT.onError(e, uc); } }) .build(); @@ -555,4 +534,21 @@ public void onError(IOException e, HttpURLConnection uc) throws IOException { } assertThat(mockGitHub.getRequestCount(), equalTo(2)); } + + private GitHubBuilder getGitHubWithAbuseLimitHandler(AbuseLimitHandler abuseLimitHandler) { + return getGitHubBuilder().withEndpoint(mockGitHub.apiServer().baseUrl()) + .withAbuseLimitHandler(abuseLimitHandler); + } + + /** + * Test class wrapping the deprecated AbuseLimitHandler to make editing easier. + */ + public static abstract class TestAbuseLimitHandler extends AbuseLimitHandler { + /** + * Default Constructor + */ + public TestAbuseLimitHandler() { + } + } + } diff --git a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/2-r_h_t_fail.json b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/2-r_h_t_fail.json index d1127227f9..39bc810022 100644 --- a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/2-r_h_t_fail.json +++ b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/2-r_h_t_fail.json @@ -11,17 +11,14 @@ } }, "response": { - "status": 403, + "status": 429, "body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}", "headers": { "Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}", "Content-Type": "application/json; charset=utf-8", "Server": "GitHub.com", - "Status": "403 Forbidden", - "gh-limited-by": "search-elapsed-time-shared-grouped", - "X-RateLimit-Limit": "5000", - "X-RateLimit-Remaining": "4000", - "X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}", + "Status": "429 Too Many Requests", + "Retry-After": "8", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": [ "Accept, Authorization, Cookie, X-GitHub-OTP", @@ -45,8 +42,8 @@ }, "uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", "persistent": true, - "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests", + "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1", "requiredScenarioState": "Started", - "newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests-2", + "newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1-2", "insertionIndex": 2 } \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/3-r_h_t_fail.json b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/3-r_h_t_fail.json index a2dc66b59d..643ed2e9db 100644 --- a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/3-r_h_t_fail.json +++ b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests/mappings/3-r_h_t_fail.json @@ -1,5 +1,5 @@ { - "id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "id": "574da117-6845-46d8-b2c1-4415546ca670", "name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests", "request": { "url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests", @@ -11,21 +11,23 @@ } }, "response": { - "status": 429, - "body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}", + "status": 200, + "bodyFileName": "3-r_h_t_fail.json", "headers": { "Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}", "Content-Type": "application/json; charset=utf-8", "Server": "GitHub.com", - "Status": "429 Too Many Requests", - "Retry-After": "42", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4922", + "X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": [ "Accept, Authorization, Cookie, X-GitHub-OTP", "Accept-Encoding" ], - "ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"", - "Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT", + "ETag": "W/\"858224998ac7d1fd6dcd43f73d375297\"", + "Last-Modified": "Thu, 06 Feb 2020 18:33:43 GMT", "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", "X-Accepted-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "unknown, github.v3", @@ -37,13 +39,12 @@ "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", - "X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC" + "X-GitHub-Request-Id": "CC37:2605:3FADC:4EA8C:5E3C5C02" } }, - "uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "uuid": "574da117-6845-46d8-b2c1-4415546ca670", "persistent": true, - "scenarioName": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests", - "requiredScenarioState": "Started", - "newScenarioState": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests-2", - "insertionIndex": 2 + "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1", + "requiredScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits1-2", + "insertionIndex": 3 } \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/2-r_h_t_fail.json b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/2-r_h_t_fail.json index 41af8b707d..4d22b7d4bf 100644 --- a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/2-r_h_t_fail.json +++ b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/2-r_h_t_fail.json @@ -11,17 +11,14 @@ } }, "response": { - "status": 403, + "status": 429, "body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}", "headers": { "Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}", "Content-Type": "application/json; charset=utf-8", "Server": "GitHub.com", - "Status": "403 Forbidden", - "gh-limited-by": "search-elapsed-time-shared-grouped", - "X-RateLimit-Limit": "5000", - "X-RateLimit-Remaining": "4000", - "X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}", + "Status": "429 Too Many Requests", + "Retry-After": "{{now offset='8 seconds' timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": [ "Accept, Authorization, Cookie, X-GitHub-OTP", @@ -45,8 +42,8 @@ }, "uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", "persistent": true, - "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After", + "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2", "requiredScenarioState": "Started", - "newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After-2", + "newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2-2", "insertionIndex": 2 } \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/3-r_h_t_fail.json b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/3-r_h_t_fail.json index a29ef6ac2d..f433290eab 100644 --- a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/3-r_h_t_fail.json +++ b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After/mappings/3-r_h_t_fail.json @@ -1,5 +1,5 @@ { - "id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "id": "574da117-6845-46d8-b2c1-4415546ca670", "name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After", "request": { "url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After", @@ -11,21 +11,23 @@ } }, "response": { - "status": 429, - "body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}", + "status": 200, + "bodyFileName": "3-r_h_t_fail.json", "headers": { "Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}", "Content-Type": "application/json; charset=utf-8", "Server": "GitHub.com", - "Status": "429 Too Many Requests", - "Retry-After": "Mon, 21 Oct 2115 07:28:00 GMT", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4922", + "X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": [ "Accept, Authorization, Cookie, X-GitHub-OTP", "Accept-Encoding" ], - "ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"", - "Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT", + "ETag": "W/\"858224998ac7d1fd6dcd43f73d375297\"", + "Last-Modified": "Thu, 06 Feb 2020 18:33:43 GMT", "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", "X-Accepted-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "unknown, github.v3", @@ -37,13 +39,12 @@ "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", - "X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC" + "X-GitHub-Request-Id": "CC37:2605:3FADC:4EA8C:5E3C5C02" } }, - "uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "uuid": "574da117-6845-46d8-b2c1-4415546ca670", "persistent": true, - "scenarioName": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After", - "requiredScenarioState": "Started", - "newScenarioState": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_Date_Retry_After-2", - "insertionIndex": 2 + "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2", + "requiredScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits2-2", + "insertionIndex": 3 } \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/2-r_h_t_fail.json b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/2-r_h_t_fail.json new file mode 100644 index 0000000000..f5e2fd8e29 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/2-r_h_t_fail.json @@ -0,0 +1,49 @@ +{ + "id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After", + "request": { + "url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 429, + "body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}", + "headers": { + "Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "429 Too Many Requests", + "gh-limited-by": "search-elapsed-time-shared-grouped", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"", + "Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, gh-limited-by, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC" + } + }, + "uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "persistent": true, + "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3", + "requiredScenarioState": "Started", + "newScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3-2", + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/3-r_h_t_fail.json b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/3-r_h_t_fail.json index d6522df8e3..9d7f608e1a 100644 --- a/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/3-r_h_t_fail.json +++ b/src/test/resources/org/kohsuke/github/AbuseLimitHandlerTest/wiremock/testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After/mappings/3-r_h_t_fail.json @@ -1,5 +1,5 @@ { - "id": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "id": "574da117-6845-46d8-b2c1-4415546ca670", "name": "repos_hub4j-test-org_temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After", "request": { "url": "/repos/hub4j-test-org/temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After", @@ -11,21 +11,23 @@ } }, "response": { - "status": 429, - "body": "{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again\"}", + "status": 200, + "bodyFileName": "3-r_h_t_fail.json", "headers": { "Date": "{{now timezone='GMT' format='EEE, dd MMM yyyy HH:mm:ss z'}}", "Content-Type": "application/json; charset=utf-8", "Server": "GitHub.com", - "Status": "429 Too Many Requests", - "gh-limited-by": "search-elapsed-time-shared-grouped", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4922", + "X-RateLimit-Reset": "{{testStartDate offset='3 seconds' format='unix'}}", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": [ "Accept, Authorization, Cookie, X-GitHub-OTP", "Accept-Encoding" ], - "ETag": "W/\"7ff3c96399f7ddf6129622d675ca9935\"", - "Last-Modified": "Thu, 06 Feb 2020 18:33:37 GMT", + "ETag": "W/\"858224998ac7d1fd6dcd43f73d375297\"", + "Last-Modified": "Thu, 06 Feb 2020 18:33:43 GMT", "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion", "X-Accepted-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "unknown, github.v3", @@ -37,13 +39,12 @@ "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", - "X-GitHub-Request-Id": "CC37:2605:3F982:4E949:5E3C5BFC" + "X-GitHub-Request-Id": "CC37:2605:3FADC:4EA8C:5E3C5C02" } }, - "uuid": "79fb1092-8bf3-4274-bc8e-ca126c9d9261", + "uuid": "574da117-6845-46d8-b2c1-4415546ca670", "persistent": true, - "scenarioName": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After", - "requiredScenarioState": "Started", - "newScenarioState": "scenario-4-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits_Too_Many_Requests_No_Retry_After-2", - "insertionIndex": 2 + "scenarioName": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3", + "requiredScenarioState": "scenario-1-repos-hub4j-test-org-temp-testHandler_Wait_Secondary_Limits3-2", + "insertionIndex": 3 } \ No newline at end of file