@Test public void shouldNotDecryptSvnPasswordIfPasswordIsNotNull() throws Exception { GoCipher mockGoCipher = mock(GoCipher.class); when(mockGoCipher.encrypt("password")).thenReturn("encrypted"); when(mockGoCipher.decrypt("encrypted")).thenReturn("password"); SvnMaterial material = new SvnMaterial("/foo", "username", "password", false, mockGoCipher); material.ensureEncrypted(); when(mockGoCipher.encrypt("new_password")).thenReturn("new_encrypted"); material.setPassword("new_password"); when(mockGoCipher.decrypt("new_encrypted")).thenReturn("new_password"); assertThat(material.getPassword(), is("new_password")); }
@Test public void shouldEncryptSvnPasswordAndMarkPasswordAsNull() throws Exception { GoCipher mockGoCipher = mock(GoCipher.class); when(mockGoCipher.encrypt("password")).thenReturn("encrypted"); when(mockGoCipher.maybeReEncryptForPostConstructWithoutExceptions("encrypted")).thenReturn("encrypted"); SvnMaterial material = new SvnMaterial("/foo", "username", "password", false, mockGoCipher); material.ensureEncrypted(); assertThat(material.getPassword(), is(nullValue())); assertThat(material.getEncryptedPassword(), is("encrypted")); }
@Test public void shouldDecryptSvnPassword() throws Exception { GoCipher mockGoCipher = mock(GoCipher.class); when(mockGoCipher.decrypt("encrypted")).thenReturn("password"); when(mockGoCipher.maybeReEncryptForPostConstructWithoutExceptions("encrypted")).thenReturn("encrypted"); SvnMaterial material = new SvnMaterial("/foo", "username", null, false, mockGoCipher); ReflectionUtil.setField(material, "encryptedPassword", "encrypted"); material.ensureEncrypted(); assertThat(material.getPassword(), is("password")); }