@@ -66,22 +66,22 @@ public void setup() throws IOException {
66
66
public void sign_success_noRetry () {
67
67
byte [] expectedSignature = {0xD , 0xE , 0xA , 0xD };
68
68
69
- ImpersonatedCredentialsTest . MockIAMCredentialsServiceTransportFactory transportFactory =
70
- new ImpersonatedCredentialsTest . MockIAMCredentialsServiceTransportFactory ();
71
- transportFactory .transport .setSignedBlob (expectedSignature );
72
- transportFactory .transport .setTargetPrincipal (CLIENT_EMAIL );
73
- transportFactory .transport .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
69
+ MockIAMCredentialsServiceTransportFactory transportFactory =
70
+ new MockIAMCredentialsServiceTransportFactory ();
71
+ transportFactory .getTransport () .setSignedBlob (expectedSignature );
72
+ transportFactory .getTransport () .setTargetPrincipal (CLIENT_EMAIL );
73
+ transportFactory .getTransport () .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
74
74
75
75
byte [] signature =
76
76
IamUtils .sign (
77
77
CLIENT_EMAIL ,
78
78
credentials ,
79
- transportFactory .transport ,
79
+ transportFactory .getTransport () ,
80
80
expectedSignature ,
81
81
ImmutableMap .of ());
82
82
assertArrayEquals (expectedSignature , signature );
83
83
84
- assertEquals (1 , transportFactory .transport .getNumRequests ());
84
+ assertEquals (1 , transportFactory .getTransport () .getNumRequests ());
85
85
}
86
86
87
87
// The SignBlob RPC will retry up to three times before it gives up. This test will return two
@@ -91,28 +91,30 @@ public void sign_success_noRetry() {
91
91
public void sign_retryTwoTimes_success () {
92
92
byte [] expectedSignature = {0xD , 0xE , 0xA , 0xD };
93
93
94
- ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory transportFactory =
95
- new ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory ();
96
- transportFactory .transport .addStatusCodeAndMessage (
97
- HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
98
- transportFactory .transport .addStatusCodeAndMessage (
99
- HttpStatusCodes .STATUS_CODE_SERVICE_UNAVAILABLE , "Unavailable" );
100
- transportFactory .transport .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
101
- transportFactory .transport .setSignedBlob (expectedSignature );
102
- transportFactory .transport .setTargetPrincipal (CLIENT_EMAIL );
94
+ MockIAMCredentialsServiceTransportFactory transportFactory =
95
+ new MockIAMCredentialsServiceTransportFactory ();
96
+ transportFactory
97
+ .getTransport ()
98
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
99
+ transportFactory
100
+ .getTransport ()
101
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_SERVICE_UNAVAILABLE , "Unavailable" );
102
+ transportFactory .getTransport ().addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
103
+ transportFactory .getTransport ().setSignedBlob (expectedSignature );
104
+ transportFactory .getTransport ().setTargetPrincipal (CLIENT_EMAIL );
103
105
104
106
byte [] signature =
105
107
IamUtils .sign (
106
108
CLIENT_EMAIL ,
107
109
credentials ,
108
- transportFactory .transport ,
110
+ transportFactory .getTransport () ,
109
111
expectedSignature ,
110
112
ImmutableMap .of ());
111
113
assertArrayEquals (expectedSignature , signature );
112
114
113
115
// Expect that three requests are made (2 failures which are retries + 1 final requests which
114
116
// resulted in a successful response)
115
- assertEquals (3 , transportFactory .transport .getNumRequests ());
117
+ assertEquals (3 , transportFactory .getTransport () .getNumRequests ());
116
118
}
117
119
118
120
// The rpc will retry up to three times before it gives up. This test will enqueue three failed
@@ -122,30 +124,33 @@ public void sign_retryTwoTimes_success() {
122
124
public void sign_retryThreeTimes_success () {
123
125
byte [] expectedSignature = {0xD , 0xE , 0xA , 0xD };
124
126
125
- ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory transportFactory =
126
- new ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory ();
127
- transportFactory .transport .setSignedBlob (expectedSignature );
128
- transportFactory .transport .setTargetPrincipal (CLIENT_EMAIL );
129
- transportFactory .transport .addStatusCodeAndMessage (
130
- HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
131
- transportFactory .transport .addStatusCodeAndMessage (
132
- HttpStatusCodes .STATUS_CODE_SERVICE_UNAVAILABLE , "Unavailable" );
133
- transportFactory .transport .addStatusCodeAndMessage (
134
- HttpStatusCodes .STATUS_CODE_SERVER_ERROR , "Server Error" );
135
- transportFactory .transport .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
127
+ MockIAMCredentialsServiceTransportFactory transportFactory =
128
+ new MockIAMCredentialsServiceTransportFactory ();
129
+ transportFactory .getTransport ().setSignedBlob (expectedSignature );
130
+ transportFactory .getTransport ().setTargetPrincipal (CLIENT_EMAIL );
131
+ transportFactory
132
+ .getTransport ()
133
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
134
+ transportFactory
135
+ .getTransport ()
136
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_SERVICE_UNAVAILABLE , "Unavailable" );
137
+ transportFactory
138
+ .getTransport ()
139
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_SERVER_ERROR , "Server Error" );
140
+ transportFactory .getTransport ().addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
136
141
137
142
byte [] signature =
138
143
IamUtils .sign (
139
144
CLIENT_EMAIL ,
140
145
credentials ,
141
- transportFactory .transport ,
146
+ transportFactory .getTransport () ,
142
147
expectedSignature ,
143
148
ImmutableMap .of ());
144
149
assertArrayEquals (expectedSignature , signature );
145
150
146
151
// Expect that three requests are made (3 failures which are retried + 1 final request which
147
152
// resulted the final success response)
148
- assertEquals (4 , transportFactory .transport .getNumRequests ());
153
+ assertEquals (4 , transportFactory .getTransport () .getNumRequests ());
149
154
}
150
155
151
156
// The rpc will retry up to three times before it gives up. This test will enqueue four failed
@@ -155,19 +160,23 @@ public void sign_retryThreeTimes_success() {
155
160
public void sign_retryThreeTimes_exception () {
156
161
byte [] expectedSignature = {0xD , 0xE , 0xA , 0xD };
157
162
158
- ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory transportFactory =
159
- new ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory ();
160
- transportFactory .transport .setSignedBlob (expectedSignature );
161
- transportFactory .transport .setTargetPrincipal (CLIENT_EMAIL );
162
- transportFactory .transport .addStatusCodeAndMessage (
163
- HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
164
- transportFactory .transport .addStatusCodeAndMessage (
165
- HttpStatusCodes .STATUS_CODE_SERVICE_UNAVAILABLE , "Unavailable" );
166
- transportFactory .transport .addStatusCodeAndMessage (
167
- HttpStatusCodes .STATUS_CODE_SERVER_ERROR , "Server Error" );
168
- transportFactory .transport .addStatusCodeAndMessage (
169
- HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
170
- transportFactory .transport .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
163
+ MockIAMCredentialsServiceTransportFactory transportFactory =
164
+ new MockIAMCredentialsServiceTransportFactory ();
165
+ transportFactory .getTransport ().setSignedBlob (expectedSignature );
166
+ transportFactory .getTransport ().setTargetPrincipal (CLIENT_EMAIL );
167
+ transportFactory
168
+ .getTransport ()
169
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
170
+ transportFactory
171
+ .getTransport ()
172
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_SERVICE_UNAVAILABLE , "Unavailable" );
173
+ transportFactory
174
+ .getTransport ()
175
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_SERVER_ERROR , "Server Error" );
176
+ transportFactory
177
+ .getTransport ()
178
+ .addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_BAD_GATEWAY , "Bad Gateway" );
179
+ transportFactory .getTransport ().addStatusCodeAndMessage (HttpStatusCodes .STATUS_CODE_OK , "" );
171
180
172
181
ServiceAccountSigner .SigningException exception =
173
182
assertThrows (
@@ -176,7 +185,7 @@ public void sign_retryThreeTimes_exception() {
176
185
IamUtils .sign (
177
186
CLIENT_EMAIL ,
178
187
credentials ,
179
- transportFactory .transport ,
188
+ transportFactory .getTransport () ,
180
189
expectedSignature ,
181
190
ImmutableMap .of ()));
182
191
assertTrue (exception .getMessage ().contains ("Failed to sign the provided bytes" ));
@@ -188,19 +197,21 @@ public void sign_retryThreeTimes_exception() {
188
197
189
198
// Expect that three requests are made (3 failures which are retried + 1 final request which
190
199
// resulted in another failed response)
191
- assertEquals (4 , transportFactory .transport .getNumRequests ());
200
+ assertEquals (4 , transportFactory .getTransport () .getNumRequests ());
192
201
}
193
202
194
203
@ Test
195
204
public void sign_4xxError_noRetry_exception () {
196
205
byte [] expectedSignature = {0xD , 0xE , 0xA , 0xD };
197
206
198
- ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory transportFactory =
199
- new ImpersonatedCredentialsTest .MockIAMCredentialsServiceTransportFactory ();
200
- transportFactory .transport .setSignedBlob (expectedSignature );
201
- transportFactory .transport .setTargetPrincipal (CLIENT_EMAIL );
202
- transportFactory .transport .addStatusCodeAndMessage (
203
- HttpStatusCodes .STATUS_CODE_UNAUTHORIZED , "Failed to sign the provided bytes" );
207
+ MockIAMCredentialsServiceTransportFactory transportFactory =
208
+ new MockIAMCredentialsServiceTransportFactory ();
209
+ transportFactory .getTransport ().setSignedBlob (expectedSignature );
210
+ transportFactory .getTransport ().setTargetPrincipal (CLIENT_EMAIL );
211
+ transportFactory
212
+ .getTransport ()
213
+ .addStatusCodeAndMessage (
214
+ HttpStatusCodes .STATUS_CODE_UNAUTHORIZED , "Failed to sign the provided bytes" );
204
215
205
216
ServiceAccountSigner .SigningException exception =
206
217
assertThrows (
@@ -209,7 +220,7 @@ public void sign_4xxError_noRetry_exception() {
209
220
IamUtils .sign (
210
221
CLIENT_EMAIL ,
211
222
credentials ,
212
- transportFactory .transport ,
223
+ transportFactory .getTransport () ,
213
224
expectedSignature ,
214
225
ImmutableMap .of ()));
215
226
assertTrue (exception .getMessage ().contains ("Failed to sign the provided bytes" ));
@@ -220,6 +231,6 @@ public void sign_4xxError_noRetry_exception() {
220
231
.contains ("Error code 401 trying to sign provided bytes:" ));
221
232
222
233
// Only one request will have been made for a 4xx error (no retries)
223
- assertEquals (1 , transportFactory .transport .getNumRequests ());
234
+ assertEquals (1 , transportFactory .getTransport () .getNumRequests ());
224
235
}
225
236
}
0 commit comments