Skip to content

Commit 38d5bd0

Browse files
committed
Add tests
1 parent fee9689 commit 38d5bd0

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

x-pack/plugin/fleet/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/fleet/30_secrets_post.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
fleet.delete_secret:
88
id: $id
99

10+
---
11+
"Create Fleet Secret with multiple values":
12+
- do:
13+
fleet.post_secret:
14+
body: '{"value": ["test secret 1", "test secret 2"]}'
15+
- set: { id: id }
16+
- do:
17+
fleet.delete_secret:
18+
id: $id
19+
1020
---
1121
"Create secret fails for unprivileged user":
1222
- skip:

x-pack/plugin/fleet/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/fleet/40_secrets_get.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@
1818
fleet.delete_secret:
1919
id: $id
2020

21+
---
22+
"Get Fleet Secret with multiple values":
23+
- do:
24+
fleet.post_secret:
25+
body: '{"value": ["test secret 1", "test secret 2"]}'
26+
- set: { id: id }
27+
# search node needs to be available for fleet.get_secret to work in stateless.
28+
# The `.fleet-secrets` index is created on demand, and its search replica starts out unassigned,
29+
# so wait_for_no_uninitialized_shards can miss it.
30+
- do:
31+
cluster.health:
32+
wait_for_active_shards: all
33+
- do:
34+
fleet.get_secret:
35+
id: $id
36+
- match: { id: $id }
37+
- match: { value: ["test secret 1", "test secret 2"] }
38+
- do:
39+
fleet.delete_secret:
40+
id: $id
41+
2142
---
2243
"Get non existent Fleet Secret":
2344
- do:

x-pack/plugin/fleet/src/test/java/org/elasticsearch/xpack/fleet/action/GetSecretResponseTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
package org.elasticsearch.xpack.fleet.action;
99

10+
import org.elasticsearch.action.ActionResponseValidationException;
1011
import org.elasticsearch.common.io.stream.Writeable;
1112
import org.elasticsearch.test.AbstractWireSerializingTestCase;
1213

14+
import static org.junit.Assert.assertArrayEquals;
15+
1316
public class GetSecretResponseTests extends AbstractWireSerializingTestCase<GetSecretResponse> {
1417

1518
@Override
@@ -26,4 +29,12 @@ protected GetSecretResponse createTestInstance() {
2629
protected GetSecretResponse mutateInstance(GetSecretResponse instance) {
2730
return new GetSecretResponse(instance.id(), randomAlphaOfLength(10));
2831
}
32+
33+
public void testValidateResponseWithMultiValue() {
34+
String[] secrets = {"secret1", "secret2"};
35+
GetSecretResponse res = new GetSecretResponse(randomAlphaOfLength(10), secrets);
36+
ActionResponseValidationException e = res.validate();
37+
assertNull(e);
38+
assertArrayEquals(secrets, (String[]) res.value());
39+
}
2940
}

x-pack/plugin/fleet/src/test/java/org/elasticsearch/xpack/fleet/action/PostSecretRequestTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public void testValidateRequest() {
3737
assertNull(e);
3838
}
3939

40+
public void testValidateRequestWithMultiValue() {
41+
PostSecretRequest req = new PostSecretRequest(["secret1", "secret2"]);
42+
ActionRequestValidationException e = req.validate();
43+
assertNull(e);
44+
}
45+
4046
public void testValidateRequestWithoutValue() {
4147
PostSecretRequest req = new PostSecretRequest((String) null);
4248
ActionRequestValidationException e = req.validate();

0 commit comments

Comments
 (0)