Skip to content

Commit 3a2343e

Browse files
committed
Add nonce value to AuthResponse
1 parent e07c454 commit 3a2343e

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/main/java/com/bettercloud/vault/response/AuthResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class AuthResponse extends VaultResponse {
2424
private String appId;
2525
private String userId;
2626
private String username;
27+
private String nonce;
2728

2829
/**
2930
* This constructor simply exposes the common base class constructor.
@@ -47,6 +48,7 @@ public AuthResponse(final RestResponse restResponse, final int retries) {
4748
appId = metadata.getString("app-id", "");
4849
userId = metadata.getString("user-id", "");
4950
username = metadata.getString("username", "");
51+
nonce = metadata.getString("nonce", "");
5052
}
5153
authClientToken = authJsonObject.getString("client_token", "");
5254
final JsonArray authPoliciesJsonArray = authJsonObject.get("policies").asArray();
@@ -89,4 +91,6 @@ public String getAppId() {
8991
public String getUserId() {
9092
return userId;
9193
}
94+
95+
public String getNonce() { return nonce; }
9296
}

src/test/java/com/bettercloud/vault/vault/api/AuthBackendAwsTests.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.bettercloud.vault.VaultConfig;
55
import com.bettercloud.vault.VaultException;
66
import com.bettercloud.vault.json.JsonObject;
7+
import com.bettercloud.vault.response.AuthResponse;
78
import com.bettercloud.vault.vault.VaultTestUtils;
89
import com.bettercloud.vault.vault.mock.AuthRequestValidatingMockVault;
910
import org.eclipse.jetty.server.Server;
@@ -41,15 +42,19 @@ public void testLoginByAwsEc2Id() throws Exception {
4142
final Vault vault = new Vault(vaultConfig);
4243

4344
String token = null;
45+
String nonce = null;
4446
try {
45-
token = vault.auth()
46-
.loginByAwsEc2("role", "identity", "signature", null, null)
47-
.getAuthClientToken();
47+
AuthResponse response = vault.auth()
48+
.loginByAwsEc2("role", "identity", "signature", null, null);
49+
nonce = response.getNonce();
50+
token = response.getAuthClientToken();
4851
} catch (VaultException ignored) {
4952
}
5053

5154
server.stop();
5255

56+
assertNotNull(nonce);
57+
assertEquals("5defbf9e-a8f9-3063-bdfc-54b7a42a1f95", nonce.trim());
5358
assertNotNull(token);
5459
assertEquals("c9368254-3f21-aded-8a6f-7c818e81b17a", token.trim());
5560

@@ -80,15 +85,18 @@ public void testLoginByAwsEc2Pkcs7() throws Exception {
8085
System.out.println("Running Aws EC2 test");
8186

8287
String token = null;
88+
String nonce = null;
8389
try {
84-
token = vault.auth()
85-
.loginByAwsEc2("role", "pkcs7", null, null)
86-
.getAuthClientToken();
90+
AuthResponse response = vault.auth().loginByAwsEc2("role", "pkcs7", null, null);
91+
nonce = response.getNonce();
92+
token = response.getAuthClientToken();
8793
} catch (VaultException ignored) {
8894
}
8995

9096
server.stop();
9197

98+
assertNotNull(nonce);
99+
assertEquals("5defbf9e-a8f9-3063-bdfc-54b7a42a1f95", nonce.trim());
92100
assertNotNull(token);
93101
assertEquals("c9368254-3f21-aded-8a6f-7c818e81b17a", token.trim());
94102
}
@@ -114,13 +122,16 @@ public void testLoginByAwsIam() throws Exception {
114122
.build();
115123
final Vault vault = new Vault(vaultConfig);
116124

117-
final String token = vault.auth()
125+
AuthResponse response = vault.auth()
118126
.loginByAwsIam("role", "url", "body", "headers",
119-
null)
120-
.getAuthClientToken();
127+
null);
128+
final String nonce = response.getNonce();
129+
final String token = response.getAuthClientToken();
121130

122131
server.stop();
123132

133+
assertNotNull(nonce);
134+
assertEquals("5defbf9e-a8f9-3063-bdfc-54b7a42a1f95", nonce.trim());
124135
assertNotNull(token);
125136
assertEquals("c9368254-3f21-aded-8a6f-7c818e81b17a", token.trim());
126137
}

src/test/java/com/bettercloud/vault/vault/mock/AuthRequestValidatingMockVault.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class AuthRequestValidatingMockVault extends MockVault {
1919
" \"instance_id\": \"i-de0f1344\",\n" +
2020
" \"ami_id\": \"ami-fce36983\",\n" +
2121
" \"role\": \"dev-role\",\n" +
22-
" \"auth_type\": \"ec2\"\n" +
22+
" \"auth_type\": \"ec2\",\n" +
23+
" \"nonce\": \"5defbf9e-a8f9-3063-bdfc-54b7a42a1f95\"\n" +
2324
" },\n" +
2425
" \"policies\": [\n" +
2526
" \"default\",\n" +

0 commit comments

Comments
 (0)