@@ -57,8 +57,10 @@ internal class MemoryCloudDriverCacheTest {
57
57
)
58
58
59
59
val certificates = listOf (
60
- Certificate (" cert-1" , " arn:cert-1" ),
61
- Certificate (" cert-2" , " arn:cert-2" )
60
+ Certificate (" cert-1" , " prod" , " arn:prod:cert-1" ),
61
+ Certificate (" cert-2" , " prod" , " arn:prod:cert-2" ),
62
+ Certificate (" cert-1" , " test" , " arn:test:cert-1" ),
63
+ Certificate (" cert-2" , " test" , " arn:test:cert-2" )
62
64
)
63
65
64
66
@Test
@@ -224,26 +226,44 @@ internal class MemoryCloudDriverCacheTest {
224
226
225
227
@ParameterizedTest
226
228
@ValueSource(strings = [" cert-1" , " cert-2" ])
227
- fun `certificates are looked up from CloudDriver when requested by name` (name : String ) {
229
+ fun `certificates are looked up from CloudDriver when requested by account and name` (name : String ) {
228
230
every { cloudDriver.getCertificates() } returns certificates
229
231
230
- expectThat(subject.certificateByName( name))
232
+ expectThat(subject.certificateByAccountAndName( " test " , name))
231
233
.get { serverCertificateName } isEqualTo name
232
234
}
233
235
236
+ @ParameterizedTest
237
+ @ValueSource(strings = [" prod" , " test" ])
238
+ fun `certificates are correctly distinguished by account` (account : String ) {
239
+ every { cloudDriver.getCertificates() } returns certificates
240
+
241
+ expectThat(subject.certificateByAccountAndName(account, " cert-1" )) {
242
+ get { serverCertificateName } isEqualTo " cert-1"
243
+ get { account } isEqualTo account
244
+ }
245
+ }
246
+
234
247
@Test
235
248
fun `an unknown certificate name throws an exception` () {
236
249
every { cloudDriver.getCertificates() } returns certificates
237
250
238
- expectThrows<ResourceNotFound > { subject.certificateByName(" does-not-exist" ) }
251
+ expectThrows<ResourceNotFound > { subject.certificateByAccountAndName(" test" , " does-not-exist" ) }
252
+ }
253
+
254
+ @Test
255
+ fun `an unknown account for a known certificate name throws an exception` () {
256
+ every { cloudDriver.getCertificates() } returns certificates
257
+
258
+ expectThrows<ResourceNotFound > { subject.certificateByAccountAndName(" fnord" , " cert-1" ) }
239
259
}
240
260
241
261
@ParameterizedTest
242
262
@ValueSource(strings = [" cert-1" , " cert-2" ])
243
263
fun `subsequent requests for a certificate by name hit the cache` (name : String ) {
244
264
every { cloudDriver.getCertificates() } returns certificates
245
265
246
- repeat(4 ) { subject.certificateByName( name) }
266
+ repeat(4 ) { subject.certificateByAccountAndName( " test " , name) }
247
267
248
268
verify(exactly = 1 ) { cloudDriver.getCertificates() }
249
269
}
@@ -256,7 +276,7 @@ internal class MemoryCloudDriverCacheTest {
256
276
257
277
listOf (" cert-1" , " cert-2" )
258
278
.forEach {
259
- subject.certificateByName( it)
279
+ subject.certificateByAccountAndName( " test " , it)
260
280
// this test can be vulnerable to an occasional race condition where the 2nd read misses the
261
281
// cache (seemingly due to the way the bulk load works). This seems to be sufficient to
262
282
// prevent it
@@ -267,7 +287,7 @@ internal class MemoryCloudDriverCacheTest {
267
287
}
268
288
269
289
@ParameterizedTest
270
- @ValueSource(strings = [" arn:cert-1" , " arn:cert-2" ])
290
+ @ValueSource(strings = [" arn:prod: cert-1" , " arn:prod:cert-2 " , " arn:test:cert-1 " , " arn:test :cert-2" ])
271
291
fun `certificates are looked up from CloudDriver when requested by ARN` (arn : String ) {
272
292
every { cloudDriver.getCertificates() } returns certificates
273
293
@@ -283,7 +303,7 @@ internal class MemoryCloudDriverCacheTest {
283
303
}
284
304
285
305
@ParameterizedTest
286
- @ValueSource(strings = [" arn:cert-1" , " arn:cert-2" ])
306
+ @ValueSource(strings = [" arn:prod: cert-1" , " arn:prod:cert-2 " , " arn:test:cert-1 " , " arn:test :cert-2" ])
287
307
fun `subsequent requests for a certificate by ARN hit the cache` (arn : String ) {
288
308
every { cloudDriver.getCertificates() } returns certificates
289
309
@@ -298,7 +318,7 @@ internal class MemoryCloudDriverCacheTest {
298
318
fun `all certs are cached at once when requested by ARN` () {
299
319
every { cloudDriver.getCertificates() } returns certificates
300
320
301
- listOf (" arn:cert-1" , " arn:cert-2" )
321
+ listOf (" arn:prod: cert-1" , " arn:prod :cert-2" )
302
322
.forEach {
303
323
subject.certificateByArn(it)
304
324
// this test can be vulnerable to an occasional race condition where the 2nd read misses the
0 commit comments