Search in sources :

Example 1 with RemoteConfigCollection

use of uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection in project verify-hub by alphagov.

the class S3ConfigSourceTest method getRemoteConfigOnlyRetrievesNewContentWhenLastModifiedChanges.

@Test
public void getRemoteConfigOnlyRetrievesNewContentWhenLastModifiedChanges() throws Exception {
    SelfServiceConfig selfServiceConfig = objectMapper.readValue(selfServiceConfigShortCacheJson, SelfServiceConfig.class);
    when(s3Client.getObject(new GetObjectRequest(BUCKET_NAME, OBJECT_KEY))).thenReturn(s3Object);
    when(s3Object.getObjectContent()).thenReturn(getObjectStream("/remote-test-config.json"));
    when(s3Object.getObjectMetadata()).thenReturn(objectMetadata);
    when(objectMetadata.getLastModified()).thenReturn(Date.from(Instant.now().minusMillis(10000)));
    S3ConfigSource testSource = new S3ConfigSource(selfServiceConfig, s3Client, objectMapper);
    var testCacheLoader = testSource.getCacheLoader();
    RemoteConfigCollection result1 = testSource.getRemoteConfig();
    ListenableFuture<RemoteConfigCollection> task = testCacheLoader.reload("test", result1);
    while (!task.isDone()) {
        Thread.yield();
    }
    RemoteConfigCollection result2 = task.get();
    assertThat((result1 == result2)).isTrue();
    verify(s3Object, times(1)).getObjectContent();
    when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(s3Object2);
    when(s3Object2.getObjectMetadata()).thenReturn(objectMetadata2);
    when(s3Object2.getObjectContent()).thenReturn(getObjectStream("/remote-test-config.json"));
    when(objectMetadata2.getLastModified()).thenReturn(Date.from(Instant.now()));
    ListenableFuture<RemoteConfigCollection> task2 = testCacheLoader.reload("test", result1);
    while (!task2.isDone()) {
        Thread.yield();
    }
    verify(s3Object2, times(1)).getObjectContent();
    verify(objectMetadata2, times(1)).getLastModified();
}
Also used : RemoteConfigCollection(uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection) SelfServiceConfig(uk.gov.ida.hub.config.configuration.SelfServiceConfig) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) Test(org.junit.jupiter.api.Test)

Example 2 with RemoteConfigCollection

use of uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection in project verify-hub by alphagov.

the class S3ConfigSourceTest method getRemoteConfigReturnsRemoteConfigCollection.

@Test
public /**
 * Tests to make sure we can process the JSON to an object
 */
void getRemoteConfigReturnsRemoteConfigCollection() throws Exception {
    SelfServiceConfig selfServiceConfig = objectMapper.readValue(selfServiceConfigEnabledJson, SelfServiceConfig.class);
    when(s3Client.getObject(new GetObjectRequest(BUCKET_NAME, OBJECT_KEY))).thenReturn(s3Object);
    when(s3Object.getObjectContent()).thenReturn(getObjectStream("/remote-test-config.json"));
    when(s3Object.getObjectMetadata()).thenReturn(objectMetadata);
    when(objectMetadata.getLastModified()).thenReturn(new Date());
    S3ConfigSource testSource = new S3ConfigSource(selfServiceConfig, s3Client, objectMapper);
    RemoteConfigCollection result = testSource.getRemoteConfig();
    Map<String, RemoteMatchingServiceConfig> msConfigs = result.getMatchingServiceAdapters();
    assertThat(msConfigs.size()).isEqualTo(3);
    assertThat(msConfigs.get("https://msa.bananaregistry.test.com").getName()).isEqualTo("Banana Registry MSA");
    assertThat(msConfigs.get("https://msa.bananaregistry.test.com").getEncryptionCertificate()).contains(CERT_MSA_BANANA_ENCRYPTION);
    assertThat(msConfigs.get("https://msa.bananaregistry.test.com").getSignatureVerificationCertificates().size()).isEqualTo(1);
    assertThat(msConfigs.get("https://msa.bananaregistry.test.com").getSignatureVerificationCertificates().get(0)).contains(CERT_MSA_BANANA_SIGNING);
    Map<String, RemoteServiceProviderConfig> spConfigs = result.getServiceProviders();
    assertThat(spConfigs.size()).isEqualTo(3);
    RemoteServiceProviderConfig spConfig2 = spConfigs.get("2");
    assertThat(spConfig2.getName()).isEqualTo("Apple Registry VSP");
    assertThat(spConfig2.getSignatureVerificationCertificates().size()).isEqualTo(1);
    assertThat(spConfig2.getSignatureVerificationCertificates().get(0)).contains(CERT_VSP_APPLE_SIGNING);
    RemoteServiceProviderConfig spConfig3 = spConfigs.get("3");
    assertThat(spConfig3.getName()).isEqualTo("Banana Registry VSP");
    assertThat(spConfig3.getSignatureVerificationCertificates().size()).isEqualTo(1);
    assertThat(spConfig3.getSignatureVerificationCertificates().get(0)).contains(CERT_VSP_BANANA_SIGNING);
}
Also used : RemoteConfigCollection(uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection) SelfServiceConfig(uk.gov.ida.hub.config.configuration.SelfServiceConfig) RemoteMatchingServiceConfig(uk.gov.ida.hub.config.domain.remoteconfig.RemoteMatchingServiceConfig) RemoteServiceProviderConfig(uk.gov.ida.hub.config.domain.remoteconfig.RemoteServiceProviderConfig) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with RemoteConfigCollection

use of uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection in project verify-hub by alphagov.

the class S3ConfigSourceTest method getRemoteConfigReturnsCachedConfigWhenRepeatedlyCalled.

@Test
public void getRemoteConfigReturnsCachedConfigWhenRepeatedlyCalled() throws IOException {
    SelfServiceConfig selfServiceConfig = objectMapper.readValue(selfServiceConfigEnabledJson, SelfServiceConfig.class);
    when(s3Client.getObject(new GetObjectRequest(BUCKET_NAME, OBJECT_KEY))).thenReturn(s3Object);
    when(s3Object.getObjectContent()).thenReturn(getObjectStream("/remote-test-config.json"));
    when(s3Object.getObjectMetadata()).thenReturn(objectMetadata);
    when(objectMetadata.getLastModified()).thenReturn(new Date());
    S3ConfigSource testSource = new S3ConfigSource(selfServiceConfig, s3Client, objectMapper);
    RemoteConfigCollection result1 = testSource.getRemoteConfig();
    RemoteConfigCollection result2 = testSource.getRemoteConfig();
    verify(s3Object, times(1)).getObjectContent();
    assertThat(result1 == result2);
}
Also used : RemoteConfigCollection(uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection) SelfServiceConfig(uk.gov.ida.hub.config.configuration.SelfServiceConfig) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with RemoteConfigCollection

use of uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection in project verify-hub by alphagov.

the class ManagedEntityConfigRepositoryTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    URL url = this.getClass().getResource("/remote-test-config.json");
    File initialFile = new File(url.getFile());
    InputStream inputStream = new FileInputStream(initialFile);
    ObjectMapper om = new ObjectMapper();
    SelfServiceMetadata selfServiceMetadata = om.readValue(inputStream, SelfServiceMetadata.class);
    RemoteConfigCollection remoteConfigCollection = new RemoteConfigCollection(null, selfServiceMetadata);
    when(s3ConfigSource.getRemoteConfig()).thenReturn(remoteConfigCollection);
    when(localConfigRepository.getData(LOCAL_ONLY_ENTITY_ID)).thenReturn(Optional.of(localOnlyTransaction));
    when(localConfigRepository.getData(REMOTE_ENABLED_ENTITY_ID)).thenReturn(Optional.of(remoteEnabledTransaction));
    when(localConfigRepository.getData(REMOTE_DISABLED_ENTITY_ID)).thenReturn(Optional.of(remoteDisabledTransaction));
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SelfServiceMetadata(uk.gov.ida.hub.config.domain.remoteconfig.SelfServiceMetadata) RemoteConfigCollection(uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with RemoteConfigCollection

use of uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection in project verify-hub by alphagov.

the class S3ConfigSourceTest method getRemoteConfigReturnsEmptyRemoteConfigWhenSelfServiceDisabled.

@Test
public void getRemoteConfigReturnsEmptyRemoteConfigWhenSelfServiceDisabled() throws IOException {
    SelfServiceConfig selfServiceConfig = objectMapper.readValue(selfServiceConfigDisabledJson, SelfServiceConfig.class);
    S3ConfigSource testSource = new S3ConfigSource(selfServiceConfig, null, objectMapper);
    RemoteConfigCollection result = testSource.getRemoteConfig();
    assertThat(result).isNotNull();
    assertThat(result.getServiceProviders().size()).isEqualTo(0);
    assertThat(result.getMatchingServiceAdapters().size()).isEqualTo(0);
    assertThat(result.getConnectedServices().size()).isEqualTo(0);
}
Also used : RemoteConfigCollection(uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection) SelfServiceConfig(uk.gov.ida.hub.config.configuration.SelfServiceConfig) Test(org.junit.jupiter.api.Test)

Aggregations

RemoteConfigCollection (uk.gov.ida.hub.config.domain.remoteconfig.RemoteConfigCollection)5 Test (org.junit.jupiter.api.Test)4 SelfServiceConfig (uk.gov.ida.hub.config.configuration.SelfServiceConfig)4 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 Date (java.util.Date)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 RemoteMatchingServiceConfig (uk.gov.ida.hub.config.domain.remoteconfig.RemoteMatchingServiceConfig)1 RemoteServiceProviderConfig (uk.gov.ida.hub.config.domain.remoteconfig.RemoteServiceProviderConfig)1 SelfServiceMetadata (uk.gov.ida.hub.config.domain.remoteconfig.SelfServiceMetadata)1