From 056c8fce1a91a8f961829fa97f8aa79f1c782b82 Mon Sep 17 00:00:00 2001 From: David Leifker Date: Wed, 18 Jan 2023 16:16:02 -0600 Subject: [PATCH] fix(secret-service): fix default encrypt key --- .../src/main/resources/application.yml | 2 +- .../secret/SecretServiceFactoryTest.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 metadata-service/factories/src/test/java/com/linkedin/gms/factory/secret/SecretServiceFactoryTest.java diff --git a/metadata-service/factories/src/main/resources/application.yml b/metadata-service/factories/src/main/resources/application.yml index 7526e315e10f2..d4c5efd0be5b4 100644 --- a/metadata-service/factories/src/main/resources/application.yml +++ b/metadata-service/factories/src/main/resources/application.yml @@ -44,7 +44,7 @@ telemetry: enabledServer: ${DATAHUB_TELEMETRY_ENABLED:true} secretService: - encryptionKey: "#{systemEnvironment['SECRET_SERVICE_ENCRYPTION_KEY']}:ENCRYPTION_KEY" + encryptionKey: "#{systemEnvironment['SECRET_SERVICE_ENCRYPTION_KEY'] ?: 'ENCRYPTION_KEY'}" datahub: serverType: ${DATAHUB_SERVER_TYPE:prod} diff --git a/metadata-service/factories/src/test/java/com/linkedin/gms/factory/secret/SecretServiceFactoryTest.java b/metadata-service/factories/src/test/java/com/linkedin/gms/factory/secret/SecretServiceFactoryTest.java new file mode 100644 index 0000000000000..b04b9e037be23 --- /dev/null +++ b/metadata-service/factories/src/test/java/com/linkedin/gms/factory/secret/SecretServiceFactoryTest.java @@ -0,0 +1,34 @@ +package com.linkedin.gms.factory.secret; + +import com.linkedin.metadata.secret.SecretService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +@TestPropertySource(locations = "classpath:/application.yml") +@SpringBootTest(classes = {SecretServiceFactory.class}) +public class SecretServiceFactoryTest extends AbstractTestNGSpringContextTests { + + @Value("${secretService.encryptionKey}") + private String encryptionKey; + + @Autowired + SecretService test; + + @Test + void testInjection() throws IOException { + assertEquals(encryptionKey, "ENCRYPTION_KEY"); + assertNotNull(test); + assertEquals(test.getHashedPassword("".getBytes(StandardCharsets.UTF_8), "password"), + "XohImNooBHFR0OVvjcYpJ3NgPQ1qq73WKhHvch0VQtg="); + } +}