Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nonce value to AuthResponse #168

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AuthResponse extends VaultResponse {
private String appId;
private String userId;
private String username;
private String nonce;

/**
* This constructor simply exposes the common base class constructor.
Expand All @@ -47,6 +48,7 @@ public AuthResponse(final RestResponse restResponse, final int retries) {
appId = metadata.getString("app-id", "");
userId = metadata.getString("user-id", "");
username = metadata.getString("username", "");
nonce = metadata.getString("nonce", "");
}
authClientToken = authJsonObject.getString("client_token", "");
final JsonArray authPoliciesJsonArray = authJsonObject.get("policies").asArray();
Expand Down Expand Up @@ -89,4 +91,6 @@ public String getAppId() {
public String getUserId() {
return userId;
}

public String getNonce() { return nonce; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.bettercloud.vault.VaultConfig;
import com.bettercloud.vault.VaultException;
import com.bettercloud.vault.json.JsonObject;
import com.bettercloud.vault.response.AuthResponse;
import com.bettercloud.vault.vault.VaultTestUtils;
import com.bettercloud.vault.vault.mock.AuthRequestValidatingMockVault;
import org.eclipse.jetty.server.Server;
Expand Down Expand Up @@ -41,15 +42,19 @@ public void testLoginByAwsEc2Id() throws Exception {
final Vault vault = new Vault(vaultConfig);

String token = null;
String nonce = null;
try {
token = vault.auth()
.loginByAwsEc2("role", "identity", "signature", null, null)
.getAuthClientToken();
AuthResponse response = vault.auth()
.loginByAwsEc2("role", "identity", "signature", null, null);
nonce = response.getNonce();
token = response.getAuthClientToken();
} catch (VaultException ignored) {
}

server.stop();

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

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

String token = null;
String nonce = null;
try {
token = vault.auth()
.loginByAwsEc2("role", "pkcs7", null, null)
.getAuthClientToken();
AuthResponse response = vault.auth().loginByAwsEc2("role", "pkcs7", null, null);
nonce = response.getNonce();
token = response.getAuthClientToken();
} catch (VaultException ignored) {
}

server.stop();

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

final String token = vault.auth()
AuthResponse response = vault.auth()
.loginByAwsIam("role", "url", "body", "headers",
null)
.getAuthClientToken();
null);
final String nonce = response.getNonce();
final String token = response.getAuthClientToken();

server.stop();

assertNotNull(nonce);
assertEquals("5defbf9e-a8f9-3063-bdfc-54b7a42a1f95", nonce.trim());
assertNotNull(token);
assertEquals("c9368254-3f21-aded-8a6f-7c818e81b17a", token.trim());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class AuthRequestValidatingMockVault extends MockVault {
" \"instance_id\": \"i-de0f1344\",\n" +
" \"ami_id\": \"ami-fce36983\",\n" +
" \"role\": \"dev-role\",\n" +
" \"auth_type\": \"ec2\"\n" +
" \"auth_type\": \"ec2\",\n" +
" \"nonce\": \"5defbf9e-a8f9-3063-bdfc-54b7a42a1f95\"\n" +
" },\n" +
" \"policies\": [\n" +
" \"default\",\n" +
Expand Down