eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1861211075


##########
polaris-core/src/test/java/org/apache/polaris/core/persistence/secrets/PrincipalSecretsGeneratorTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.persistence.secrets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doReturn;
+
+import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class PrincipalSecretsGeneratorTest {
+
+  @Test
+  void testRandomSecrets() {
+    RandomPrincipalSecretsGenerator rpsg = new 
RandomPrincipalSecretsGenerator("realm");
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testRandomSecretsNullRealm() {
+    RandomPrincipalSecretsGenerator rpsg = new 
RandomPrincipalSecretsGenerator(null);
+    PolarisPrincipalSecrets s = rpsg.produceSecrets("name1", 123);
+    assertThat(s).isNotNull();
+    assertThat(s.getPrincipalId()).isEqualTo(123);
+    assertThat(s.getPrincipalClientId()).isNotNull();
+    assertThat(s.getMainSecret()).isNotNull();
+    assertThat(s.getSecondarySecret()).isNotNull();
+  }
+
+  @Test
+  void testEnvVariableSecrets() {
+    EnvVariablePrincipalSecretsGenerator psg =
+        Mockito.spy(new EnvVariablePrincipalSecretsGenerator("REALM"));
+
+    String clientIdKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_ID";
+    String clientSecretKey = "POLARIS_BOOTSTRAP_REALM_PRINCIPAL_CLIENT_SECRET";
+
+    doReturn("test-id").when(psg).getEnvironmentVariable(clientIdKey);

Review Comment:
   I like this idea, but my concern is that 
`EnvVariablePrincipalSecretsGenerator` essentially becomes 
`MapPrincipalSecretsGenerator` with that approach. I would rather not place the 
burden on its callers to do the `fromEnv` / `getEnv`; this seems like the exact 
responsibility we would like `EnvVariablePrincipalSecretsGenerator` to take on.
   
   Indeed, if we later add command-line options to `bootstrap` that allow you 
to provide credentials, would we use the  
`EnvVariablePrincipalSecretsGenerator` for that? If it takes a map, we could



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to