Skip to content

Commit

Permalink
Fix slackapi#1373 LogsResponse in AuditClient returns "ok: false" whe…
Browse files Browse the repository at this point in the history
…n request was a success
  • Loading branch information
seratch committed Sep 17, 2024
1 parent 46b1fcd commit b334c60
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 5 deletions.
9 changes: 8 additions & 1 deletion json-logs/raw/audit/v1/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@
"external_shared_channel_invite_request_approved",
"external_shared_channel_invite_request_denied",
"channel_tab_added",
"channel_tab_removed"
"channel_tab_removed",
"external_shared_channel_host_transferred",
"channel_template_provisioned"
],
"app": [
"app_installed",
Expand Down Expand Up @@ -502,6 +504,11 @@
"native_dlp_rule_reactivated",
"native_dlp_rule_edited",
"native_dlp_rule_action_applied"
],
"template": [
"template_created",
"template_deleted",
"template_provisioned"
]
}
}
7 changes: 7 additions & 0 deletions json-logs/raw/audit/v1/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@
"template_id": "string",
"step_configuration": "vec\u003cdict\u003cstring, mixed\u003e\u003e"
}
},
{
"type": "template",
"template": {
"id": "string",
"template_name": "string"
}
}
]
}
3 changes: 3 additions & 0 deletions json-logs/samples/audit/v1/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
],
"native_dlp": [
""
],
"template": [
""
]
},
"ok": false,
Expand Down
2 changes: 1 addition & 1 deletion json-logs/samples/audit/v1/logs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ok": false,
"ok": true,
"warning": "",
"error": "",
"needed": "",
Expand Down
4 changes: 4 additions & 0 deletions json-logs/samples/audit/v1/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
"updated_by": "",
"step_configuration": "",
"template_id": ""
},
"template": {
"id": "",
"template_name": ""
}
}
],
Expand Down
11 changes: 11 additions & 0 deletions slack-api-client/src/main/java/com/slack/api/audit/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ private Channel() {
public static final String external_shared_channel_invite_request_denied = "external_shared_channel_invite_request_denied";
public static final String channel_tab_added = "channel_tab_added";
public static final String channel_tab_removed = "channel_tab_removed";
public static final String external_shared_channel_host_transferred = "external_shared_channel_host_transferred";
public static final String channel_template_provisioned = "channel_template_provisioned";
}

public static class App {
Expand Down Expand Up @@ -591,4 +593,13 @@ private NativeDlp() {
public static final String native_dlp_rule_edited = "native_dlp_rule_edited";
public static final String native_dlp_rule_action_applied = "native_dlp_rule_action_applied";
}

public static class Template {
private Template() {
}

public static final String template_created = "template_created";
public static final String template_deleted = "template_deleted";
public static final String template_provisioned = "template_provisioned";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
public class ActionsResponse implements AuditApiResponse {
private transient String rawBody;

private boolean ok;
@Deprecated // when an error is returned, it will be an exception instead
private boolean ok = true;
@Deprecated // when an error is returned, it will be an exception instead
private String warning;
@Deprecated // when an error is returned, it will be an exception instead
private String error;
@Deprecated // when an error is returned, it will be an exception instead
private String needed;
@Deprecated // when an error is returned, it will be an exception instead
private String provided;

private Actions actions;
Expand Down Expand Up @@ -43,5 +48,6 @@ public static class Actions {
private List<String> function;
private List<String> salesElevate;
private List<String> nativeDlp;
private List<String> template;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
public class LogsResponse implements AuditApiResponse {
private transient String rawBody;

private boolean ok;
@Deprecated // when an error is returned, it will be an exception instead
private boolean ok = true;
@Deprecated // when an error is returned, it will be an exception instead
private String warning;
@Deprecated // when an error is returned, it will be an exception instead
private String error;
@Deprecated // when an error is returned, it will be an exception instead
private String needed;
@Deprecated // when an error is returned, it will be an exception instead
private String provided;

private ResponseMetadata responseMetadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
public class SchemasResponse implements AuditApiResponse {
private transient String rawBody;

private boolean ok;
@Deprecated // when an error is returned, it will be an exception instead
private boolean ok = true;
@Deprecated // when an error is returned, it will be an exception instead
private String warning;
@Deprecated // when an error is returned, it will be an exception instead
private String error;
@Deprecated // when an error is returned, it will be an exception instead
private String needed;
@Deprecated // when an error is returned, it will be an exception instead
private String provided;

private List<Schema> schemas;
Expand All @@ -36,6 +41,7 @@ public static class Schema {
private Barrier barrier;
private Canvas canvas;
private WorkflowV2 workflowV2;
private Template template;
}

@Data
Expand Down Expand Up @@ -148,4 +154,10 @@ public static class WorkflowV2 {
private String stepConfiguration;
private String templateId;
}

@Data
public static class Template {
private String id;
private String templateName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ public void getActions_detectingNewOnes() throws IOException, AuditApiException
fail("Unknown action detected - " + action);
}
}
List<String> templateNames = getAllPublicStaticFieldValues(Actions.Template.class);
for (String action : actions.getTemplate()) {
if (!templateNames.contains(action)) {
fail("Unknown action detected - " + action);
}
}
}

@Test
Expand Down Expand Up @@ -329,6 +335,7 @@ public void getLogs_paginated() throws IOException, AuditApiException {
);
assertThat(cursor, not(equalTo(response.getResponseMetadata().getNextCursor())));
assertThat(response, is(notNullValue()));
assertThat(response.isOk(), is(true));
}
}

Expand Down Expand Up @@ -368,6 +375,7 @@ static void verifyAllActions(String token, Class<?> clazz) throws Exception {
try {
LogsResponse response = slack.auditAsync(token).getLogs(req -> req.limit(500).action(action)).get();
assertThat(response.getError(), is(nullValue()));
assertThat(response.isOk(), is(true));
} catch (ExecutionException e) {
if (e.getCause() != null && e.getCause() instanceof AuditApiCompletionException) {
AuditApiCompletionException apiEx = ((AuditApiCompletionException) e.getCause());
Expand Down

0 comments on commit b334c60

Please sign in to comment.