### Question:
OpenShiftRegistryAuthHandler implements RegistryAuthHandler { @Override public AuthConfig create(RegistryAuthConfig.Kind kind, String user, String registry, Function<String, String> decryptor) { Properties props = System.getProperties(); String useOpenAuthMode = registryAuthConfig.extractFromProperties(props, kind, AUTH_USE_OPENSHIFT_AUTH); if (useOpenAuthMode != null) { boolean useOpenShift = Boolean.valueOf(useOpenAuthMode); if (!useOpenShift) { return null; } log.debug("AuthConfig: OpenShift credentials"); return validateMandatoryOpenShiftLogin(parseOpenShiftConfig()); } boolean useOpenShiftAuth = Optional.ofNullable(registryAuthConfig.getConfigForHandler(getId(), AUTH_USE_OPENSHIFT_AUTH)) .map(Boolean::parseBoolean) .orElse(false); if (useOpenShiftAuth) { log.debug("AuthConfig: OpenShift credentials"); return validateMandatoryOpenShiftLogin(parseOpenShiftConfig()); } return null; } OpenShiftRegistryAuthHandler(RegistryAuthConfig registryAuthConfig, KitLogger log); @Override String getId(); @Override AuthConfig create(RegistryAuthConfig.Kind kind, String user, String registry, Function<String, String> decryptor); static final String AUTH_USE_OPENSHIFT_AUTH; }### Answer:
@Test public void testOpenShiftConfigFromPluginConfig() throws Exception { executeWithTempHomeDir(homeDir -> { createOpenShiftConfig(homeDir,"openshift_simple_config.yaml"); AuthConfig config = handler.create(RegistryAuthConfig.Kind.PUSH, "roland", null, s -> s); verifyAuthConfig(config,"admin","token123",null); }); }
@Test public void testOpenShiftConfigFromSystemProps() throws Exception { try { System.setProperty("docker.useOpenShiftAuth", "true"); executeWithTempHomeDir(homeDir -> { createOpenShiftConfig(homeDir, "openshift_simple_config.yaml"); AuthConfig config = handler.create(RegistryAuthConfig.Kind.PUSH, "roland", null, s->s); verifyAuthConfig(config, "admin", "token123", null); }); } finally { System.getProperties().remove("docker.useOpenShiftAuth"); } }
@Test public void testOpenShiftConfigFromSystemPropsNegative() throws Exception { try { System.setProperty("docker.useOpenShiftAuth", "false"); executeWithTempHomeDir(homeDir -> { createOpenShiftConfig(homeDir, "openshift_simple_config.yaml"); AuthConfig config = handler.create(RegistryAuthConfig.Kind.PUSH, "roland", null, s->s); assertNull(config); }); } finally { System.getProperties().remove("docker.useOpenShiftAuth"); } }
@Test public void testOpenShiftConfigNotLoggedIn() throws Exception { executeWithTempHomeDir(homeDir -> { createOpenShiftConfig(homeDir,"openshift_nologin_config.yaml"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(containsString("~/.kube/config")); handler.create(RegistryAuthConfig.Kind.PUSH, "roland", null, s -> s); }); }