@VisibleForTesting ThreadLocalSettings(PropertyDefinitions definitions, Properties props, SettingLoader settingLoader) { super(definitions, new Encryption(null)); this.settingLoader = settingLoader; props.forEach((k, v) -> systemProps.put(k, v == null ? null : v.toString().trim())); // TODO something wrong about lifecycle here. It could be improved getEncryption().setPathToSecretKey(props.getProperty(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); }
@Before public void setUpSecretKey() throws Exception { logInAsSystemAdministrator(); File secretKeyFile = folder.newFile(); FileUtils.writeStringToFile(secretKeyFile, "fCVFf/JHRi8Qwu5KLNva7g=="); encryption.setPathToSecretKey(secretKeyFile.getAbsolutePath()); }
@Test public void false_when_no_secret_key() { logInAsSystemAdministrator(); encryption.setPathToSecretKey("unknown/path/to_secret_key.txt"); CheckSecretKeyWsResponse result = call(); assertThat(result.getSecretKeyAvailable()).isFalse(); }
@Test public void generate_valid_secret_key() throws IOException { GenerateSecretKeyWsResponse result = call(); String secretKey = result.getSecretKey(); File file = temporaryFolder.newFile(); FileUtils.writeStringToFile(file, secretKey); encryption.setPathToSecretKey(file.getAbsolutePath()); String encryptedValue = encryption.encrypt("my value"); String decryptedValue = encryption.decrypt(encryptedValue); assertThat(decryptedValue).isEqualTo("my value"); }
@Test public void fail_if_no_secret_key_available() { logInAsSystemAdministrator(); encryption.setPathToSecretKey("unknown/path/to/secret/key"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("No secret key available"); call("my value"); }
@Test public void json_example() throws IOException { logInAsSystemAdministrator(); File secretKeyFile = temporaryFolder.newFile(); FileUtils.writeStringToFile(secretKeyFile, "fCVFf/JHRi8Qwu5KLNva7g=="); encryption.setPathToSecretKey(secretKeyFile.getAbsolutePath()); String result = ws.newRequest().execute().getInput(); assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); }
@VisibleForTesting ThreadLocalSettings(PropertyDefinitions definitions, Properties props, SettingLoader settingLoader) { super(definitions, new Encryption(null)); this.settingLoader = settingLoader; this.systemProps = new Properties(); props.forEach((k, v) -> systemProps.put(k, v == null ? null : v.toString().trim())); // TODO something wrong about lifecycle here. It could be improved getEncryption().setPathToSecretKey(props.getProperty(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); }
public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectReferentials, DefaultAnalysisMode analysisMode) { super(batchSettings.getDefinitions()); this.projectReferentials = projectReferentials; this.analysisMode = analysisMode; getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); LoggerFactory.getLogger(ModuleSettings.class).info("Load module settings"); init(moduleDefinition, batchSettings); }
public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, PropertyDefinitions propertyDefinitions, ProjectRepositories projectReferentials, DefaultAnalysisMode mode) { super(propertyDefinitions); this.mode = mode; getEncryption().setPathToSecretKey(globalSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); this.globalSettings = globalSettings; this.projectReferentials = projectReferentials; init(reactor); }
public GlobalSettings(BootstrapProperties bootstrapProps, PropertyDefinitions propertyDefinitions, GlobalRepositories globalReferentials, DefaultAnalysisMode mode) { super(propertyDefinitions); this.mode = mode; getEncryption().setPathToSecretKey(bootstrapProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); this.bootstrapProps = bootstrapProps; this.globalReferentials = globalReferentials; init(); }
public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, PropertyDefinitions propertyDefinitions, ProjectRepositories projectRepositories, DefaultAnalysisMode mode) { super(propertyDefinitions); this.mode = mode; getEncryption().setPathToSecretKey(globalSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); this.globalSettings = globalSettings; this.projectRepositories = projectRepositories; init(reactor); }
public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectRepositories projectSettingsRepo, DefaultAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) { super(batchSettings.getDefinitions()); this.projectRepos = projectSettingsRepo; this.analysisMode = analysisMode; getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); init(moduleDefinition, batchSettings); contextReportPublisher.dumpSettings(moduleDefinition, this); }
public GlobalSettings(GlobalProperties bootstrapProps, PropertyDefinitions propertyDefinitions, GlobalRepositories globalReferentials, GlobalMode mode) { super(propertyDefinitions); this.mode = mode; getEncryption().setPathToSecretKey(bootstrapProps.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); this.bootstrapProps = bootstrapProps; this.globalReferentials = globalReferentials; init(); new DroppedPropertyChecker(this.getProperties(), DROPPED_PROPERTIES).checkDroppedProperties(); }