@Override public SecurityConfig getServerSecurityConfig() { return preprocessedConfig.server().security(); }
public void validate(CruiseConfig cruiseConfig) throws Exception { String taskRepositoryLocation = cruiseConfig.server().getCommandRepositoryLocation(); if (taskRepositoryLocation == null || isEmpty(taskRepositoryLocation.trim())) { throw new Exception("Command Repository Location cannot be empty"); } if(taskRepositoryLocation.startsWith("/") || taskRepositoryLocation.startsWith("\\") || taskRepositoryLocation.contains("~") || taskRepositoryLocation.contains(":")){ throw new Exception("Invalid Repository Location"); } String taskRepositoryRootLocation = systemEnvironment.get(COMMAND_REPOSITORY_DIRECTORY); File taskRepositoryRootDirectory = new File(taskRepositoryRootLocation); File repository = new File(taskRepositoryRootLocation, taskRepositoryLocation); if (!FileUtil.isChildOf(taskRepositoryRootDirectory, repository)) { throw new Exception(String.format("Invalid Repository Location, repository should be a subdirectory under %s", taskRepositoryRootDirectory.getAbsolutePath())); } } }
@Override public MailHost mailHost() { return serverConfig.mailHost(); }
@Override public String serverInfoToJSON(ServerConfig serverConfig) { JsonObject object = new JsonObject(); object.addProperty("server_id", serverConfig.getServerId()); object.addProperty("site_url", serverConfig.getSiteUrl().getUrl()); object.addProperty("secure_site_url", serverConfig.getSecureSiteUrl().getUrl()); return gson.toJson(object); } }
public ServerSiteUrlConfig getSiteUrlPreferablySecured() { ServerSiteUrlConfig siteUrl = getSiteUrl(); ServerSiteUrlConfig secureSiteUrlConfig = getSecureSiteUrl(); if (secureSiteUrlConfig.hasNonNullUrl()) { return secureSiteUrlConfig; } if (!secureSiteUrlConfig.hasNonNullUrl()) { return siteUrl; } return new ServerSiteUrlConfig(); }
@Test public void should_useServerId_forEqualityCheck() { ServerConfig configWithoutServerId = new ServerConfig(); ServerConfig configWithServerId = new ServerConfig(); configWithServerId.ensureServerIdExists(); assertThat(configWithoutServerId, not(configWithServerId)); }
@Test public void validate_shouldPassIfThePurgeStartAndPurgeUptoAreBothNotSet() { ServerConfig serverConfig = new ServerConfig("artifacts", new SecurityConfig()); serverConfig.validate(null); assertThat(serverConfig.errors().isEmpty(), is(true)); }
@Test public void shouldReturnBlankUrlBothSiteUrlAndSecureSiteUrlIsNotDefined(){ defaultServerConfig.setSiteUrl(null); defaultServerConfig.setSecureSiteUrl(null); assertThat(defaultServerConfig.getSiteUrlPreferablySecured().hasNonNullUrl(), is(false)); }
@Test public void shouldReturnTaskRepositoryLocation() { ServerConfig serverConfig = new ServerConfig(null,null, new ServerSiteUrlConfig("http://foo.bar:813"), new ServerSiteUrlConfig()); serverConfig.setCommandRepositoryLocation("foo"); assertThat(serverConfig.getCommandRepositoryLocation(), is("foo")); }
@Test public void shouldNotUpdatePasswordForMailHostIfNotChangedOrNull() throws IOException { File cipherFile = new SystemEnvironment().getDESCipherFile(); FileUtils.deleteQuietly(cipherFile); FileUtils.writeStringToFile(cipherFile, "269298bc31c44620", UTF_8); GoCipher goCipher = new GoCipher(); MailHost mailHost = new MailHost("abc", 12, "admin", "p", null, true, true, "anc@mail.com", "anc@mail.com", goCipher); ServerConfig serverConfig = new ServerConfig(null, mailHost, null, null); assertThat(serverConfig.mailHost().getPassword(), is("p")); String encryptedPassword = serverConfig.mailHost().getEncryptedPassword(); serverConfig.updateMailHost(new MailHost("abc", 12, "admin", "p", encryptedPassword, false /* Password Not Changed */, true, "anc@mail.com", "anc@mail.com", goCipher)); assertThat(serverConfig.mailHost().getPassword(), is("p")); assertThat(serverConfig.mailHost().getEncryptedPassword(), is(encryptedPassword)); serverConfig.updateMailHost(new MailHost("abc", 12, "admin", null, "", true, true, "anc@mail.com", "anc@mail.com")); assertThat(serverConfig.mailHost().getPassword(), is(nullValue())); assertThat(serverConfig.mailHost().getEncryptedPassword(), is(nullValue())); }
@Test public void shouldEnsureAgentAutoregisterKeyExists() throws Exception { ServerConfig serverConfig = new ServerConfig(); assertNull(serverConfig.getAgentAutoRegisterKey()); assertNotNull(serverConfig.getClass().getMethod("ensureAgentAutoregisterKeyExists").getAnnotation(PostConstruct.class)); serverConfig.ensureAgentAutoregisterKeyExists(); assertTrue(StringUtils.isNotBlank(serverConfig.getAgentAutoRegisterKey())); }
@Test public void shouldEnsureTokenGenerationKeyExists() throws Exception { ServerConfig serverConfig = new ServerConfig(); assertNull(serverConfig.getTokenGenerationKey()); assertNotNull(serverConfig.getClass().getMethod("ensureTokenGenerationKeyExists").getAnnotation(PostConstruct.class)); serverConfig.ensureTokenGenerationKeyExists(); assertTrue(StringUtils.isNotBlank(serverConfig.getTokenGenerationKey())); } }
@Test public void shouldReturnDefaultTaskRepositoryLocation() { ServerConfig serverConfig = new ServerConfig(null,null, new ServerSiteUrlConfig("http://foo.bar:813"), new ServerSiteUrlConfig()); assertThat(serverConfig.getCommandRepositoryLocation(), is("default")); }
@Before public void setUp() { defaultServerConfig = new ServerConfig("artifactsDir", new SecurityConfig()); another = new ServerConfig("artifactsDir", new SecurityConfig()); }
@Test public void shouldGetTheDefaultJobTimeoutValue() { assertThat(new ServerConfig("artifacts", new SecurityConfig(), 10.0, 20.0).getJobTimeout(), is("0")); assertThat(new ServerConfig("artifacts", new SecurityConfig(), 10.0, 20.0, "30").getJobTimeout(), is("30")); }
private Mac hmac() { if (mac == null) { try { mac = Mac.getInstance("HmacSHA256"); SecretKeySpec secretKey = new SecretKeySpec(goConfigService.serverConfig().getTokenGenerationKey().getBytes(), "HmacSHA256"); mac.init(secretKey); } catch (NoSuchAlgorithmException | InvalidKeyException e) { throw new RuntimeException(e); } } return mac; }
public boolean canCancelJobIfHung(JobIdentifier jobIdentifier) { JobConfig jobConfig = getJob(jobIdentifier); if (jobConfig == null) { return false; } String timeout = jobConfig.getTimeout(); if ("0".equals(timeout)) { return false; } if (timeout == null && !"0".equals(serverConfig().getJobTimeout())) { return true; } return timeout != null && !"0".equals(timeout); }
public String getAuthorizationServerUrl(String pluginId, String rootURL) { if (goConfigService.serverConfig().hasAnyUrlConfigured()) { rootURL = getRootUrl(goConfigService.serverConfig().getSiteUrlPreferablySecured().getUrl()); } return authorizationExtension.getAuthorizationServerUrl(pluginId, getAuthConfigs(pluginId), rootURL); }
public boolean shouldAutoRegisterAgentWith(String agentKey) { return (!StringUtils.isBlank(getAgentAutoRegisterKey())) && getAgentAutoRegisterKey().equals(agentKey); }
@Test public void shouldNotSaySecurityEnabledIfSecurityHasNoAuthenticatorsDefined() { ServerConfig serverConfig = new ServerConfig(); assertFalse("Security should not be enabled by default", serverConfig.isSecurityEnabled()); }