Skip to content

Commit 0d993ca

Browse files
test: accept GitHub's rate-limit 403 in BindingIT (#1846)
The two HTTP output binding error tests call api.github.com without a token and expected a 404. When the runner's IP has used up GitHub's unauthenticated rate limit, GitHub answers 403 instead and both tests fail. Accept either status and check the body that matches it. Signed-off-by: Javier Aliaga <javier@diagrid.io>
1 parent ef525c8 commit 0d993ca

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎sdk-tests/src/test/java/io/dapr/it/binding/http/BindingIT.java‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public void httpOutputBindingError() throws Exception {
5252
client.invokeBinding("github-http-binding-404", "get", "").block();
5353
fail("Should throw an exception");
5454
} catch (DaprException e) {
55-
assertEquals(404, e.getHttpStatusCode());
55+
assertGitHubErrorStatus(e.getHttpStatusCode());
5656
// This HTTP binding did not set `errorIfNot2XX` to false in component metadata, so the error payload is not
5757
// consistent between HTTP and gRPC.
5858
assertTrue(new String(e.getPayload()).contains(
59-
"error invoking output binding github-http-binding-404: received status code 404"));
59+
"error invoking output binding github-http-binding-404: received status code " + e.getHttpStatusCode()));
6060
}
6161
}, 10000);
6262
}
@@ -78,18 +78,25 @@ public void httpOutputBindingErrorIgnoredByComponent() throws Exception {
7878
client.invokeBinding("github-http-binding-404-success", "get", "").block();
7979
fail("Should throw an exception");
8080
} catch (DaprException e) {
81-
assertEquals(404, e.getHttpStatusCode());
81+
assertGitHubErrorStatus(e.getHttpStatusCode());
8282
// The HTTP binding must set `errorIfNot2XX` to false in component metadata for the error payload to be
8383
// consistent between HTTP and gRPC.
8484
assertTrue(new String(e.getPayload()).contains("message"));
85-
assertTrue(new String(e.getPayload()).contains("Not Found"));
85+
assertTrue(new String(e.getPayload()).contains(
86+
e.getHttpStatusCode() == 404 ? "Not Found" : "API rate limit exceeded"));
8687
assertTrue(new String(e.getPayload()).contains("documentation_url"));
8788
assertTrue(new String(e.getPayload()).contains("https://docs.github.com/rest"));
8889
}
8990
}, 10000);
9091
}
9192
}
9293

94+
// api.github.com answers 404 for an unknown path, or 403 when the runner's IP has used up the unauthenticated
95+
// rate limit. Either way the binding must pass the status and body through.
96+
private static void assertGitHubErrorStatus(int status) {
97+
assertTrue(status == 404 || status == 403, "expected 404 or 403 but was " + status);
98+
}
99+
93100
@Test
94101
public void inputOutputBinding() throws Exception {
95102
var bindingName = "sample123";

0 commit comments

Comments
 (0)