4
4
import com .bettercloud .vault .VaultConfig ;
5
5
import com .bettercloud .vault .VaultException ;
6
6
import com .bettercloud .vault .json .JsonObject ;
7
+ import com .bettercloud .vault .response .AuthResponse ;
7
8
import com .bettercloud .vault .vault .VaultTestUtils ;
8
9
import com .bettercloud .vault .vault .mock .AuthRequestValidatingMockVault ;
9
10
import org .eclipse .jetty .server .Server ;
@@ -41,15 +42,19 @@ public void testLoginByAwsEc2Id() throws Exception {
41
42
final Vault vault = new Vault (vaultConfig );
42
43
43
44
String token = null ;
45
+ String nonce = null ;
44
46
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 ();
48
51
} catch (VaultException ignored ) {
49
52
}
50
53
51
54
server .stop ();
52
55
56
+ assertNotNull (nonce );
57
+ assertEquals ("5defbf9e-a8f9-3063-bdfc-54b7a42a1f95" , nonce .trim ());
53
58
assertNotNull (token );
54
59
assertEquals ("c9368254-3f21-aded-8a6f-7c818e81b17a" , token .trim ());
55
60
@@ -80,15 +85,18 @@ public void testLoginByAwsEc2Pkcs7() throws Exception {
80
85
System .out .println ("Running Aws EC2 test" );
81
86
82
87
String token = null ;
88
+ String nonce = null ;
83
89
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 ();
87
93
} catch (VaultException ignored ) {
88
94
}
89
95
90
96
server .stop ();
91
97
98
+ assertNotNull (nonce );
99
+ assertEquals ("5defbf9e-a8f9-3063-bdfc-54b7a42a1f95" , nonce .trim ());
92
100
assertNotNull (token );
93
101
assertEquals ("c9368254-3f21-aded-8a6f-7c818e81b17a" , token .trim ());
94
102
}
@@ -114,13 +122,16 @@ public void testLoginByAwsIam() throws Exception {
114
122
.build ();
115
123
final Vault vault = new Vault (vaultConfig );
116
124
117
- final String token = vault .auth ()
125
+ AuthResponse response = vault .auth ()
118
126
.loginByAwsIam ("role" , "url" , "body" , "headers" ,
119
- null )
120
- .getAuthClientToken ();
127
+ null );
128
+ final String nonce = response .getNonce ();
129
+ final String token = response .getAuthClientToken ();
121
130
122
131
server .stop ();
123
132
133
+ assertNotNull (nonce );
134
+ assertEquals ("5defbf9e-a8f9-3063-bdfc-54b7a42a1f95" , nonce .trim ());
124
135
assertNotNull (token );
125
136
assertEquals ("c9368254-3f21-aded-8a6f-7c818e81b17a" , token .trim ());
126
137
}
0 commit comments