Skip to content

Commit 2764f52

Browse files
zimegClaude
andcommitted
fix(methods): treat blocks.validate as unauthenticated
blocks.validate requires no token or scopes (https://docs.slack.dev/reference/methods/blocks.validate), so it should not send an Authorization header. Model it like api.test: drop the token field from BlocksValidateRequest (overriding getToken() to return null) and call it through the tokenless postFormAndParseResponse path. The local BlocksTest now asserts the request round-trips (the shared mock answers a tokenless call with not_authed); end-to-end ok/errors[] behavior is covered by the remote blocks_Test. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent eb983ef commit 2764f52

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

slack-api-client/src/main/java/com/slack/api/methods/impl/MethodsClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ public AuthTeamsListResponse authTeamsList(RequestConfigurator<AuthTeamsListRequ
15621562

15631563
@Override
15641564
public BlocksValidateResponse blocksValidate(BlocksValidateRequest req) throws IOException, SlackApiException {
1565-
return postFormWithTokenAndParseResponse(toForm(req), Methods.BLOCKS_VALIDATE, getToken(req), BlocksValidateResponse.class);
1565+
return postFormAndParseResponse(toForm(req), Methods.BLOCKS_VALIDATE, BlocksValidateResponse.class);
15661566
}
15671567

15681568
@Override

slack-api-client/src/main/java/com/slack/api/methods/request/blocks/BlocksValidateRequest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
@Builder
99
public class BlocksValidateRequest implements SlackApiRequest {
1010

11-
private String token;
12-
1311
/**
1412
* A JSON-encoded string of an array of blocks to validate.
1513
*/
@@ -24,4 +22,13 @@ public class BlocksValidateRequest implements SlackApiRequest {
2422
* A JSON-encoded string of a view payload to validate.
2523
*/
2624
private String view;
25+
26+
/**
27+
* blocks.validate requires no token or scopes.
28+
* See https://docs.slack.dev/reference/methods/blocks.validate.
29+
*/
30+
@Override
31+
public String getToken() {
32+
return null;
33+
}
2734
}

slack-api-client/src/test/java/test_locally/api/methods/BlocksTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import static org.hamcrest.CoreMatchers.is;
1111
import static org.hamcrest.MatcherAssert.assertThat;
12-
import static test_locally.api.status.ApiTest.ValidToken;
1312

1413
public class BlocksTest {
1514

@@ -28,15 +27,21 @@ public void tearDown() throws Exception {
2827
server.stop();
2928
}
3029

30+
// blocks.validate is unauthenticated (no token or scopes — see
31+
// https://docs.slack.dev/reference/methods/blocks.validate), so the SDK sends no
32+
// Authorization header for it. The shared mock API gates every request on a valid token and
33+
// therefore answers a tokenless call with "not_authed"; these tests assert that the request is
34+
// built and round-trips to the endpoint, which is what a mock harness can verify without a
35+
// real Slack backend. End-to-end ok/errors[] behavior is covered by the remote blocks_Test.
3136
@Test
3237
public void validate() throws Exception {
33-
assertThat(slack.methods(ValidToken).blocksValidate(r -> r
34-
.blocks("[{\"type\":\"section\",\"text\":{\"type\":\"plain_text\",\"text\":\"Hello world\"}}]")).isOk(), is(true));
38+
assertThat(slack.methods().blocksValidate(r -> r
39+
.blocks("[{\"type\":\"section\",\"text\":{\"type\":\"plain_text\",\"text\":\"Hello world\"}}]")).getError(), is("not_authed"));
3540
}
3641

3742
@Test
3843
public void validate_async() throws Exception {
39-
assertThat(slack.methodsAsync(ValidToken).blocksValidate(r -> r
40-
.blocks("[{\"type\":\"section\",\"text\":{\"type\":\"plain_text\",\"text\":\"Hello world\"}}]")).get().isOk(), is(true));
44+
assertThat(slack.methodsAsync().blocksValidate(r -> r
45+
.blocks("[{\"type\":\"section\",\"text\":{\"type\":\"plain_text\",\"text\":\"Hello world\"}}]")).get().getError(), is("not_authed"));
4146
}
4247
}

0 commit comments

Comments
 (0)