-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1616 fixes the missing salt read from file when comparing the given …
…password
- Loading branch information
Showing
5 changed files
with
38 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,10 @@ | |
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.deegree.console.security.SaltedPassword.SHA256_PREFIX; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Torsten Friebe</a> | ||
|
@@ -18,7 +20,7 @@ public class SaltedPasswordTest { | |
public void testCreatingFromPlainPassword() throws UnsupportedEncodingException { | ||
SaltedPassword plainpassword = new SaltedPassword("foo"); | ||
String saltedPassword = new String(plainpassword.getSaltedAndHashedPassword(), StandardCharsets.UTF_8); | ||
assertThat(plainpassword.getSalt(), startsWith("$5$")); | ||
assertThat(plainpassword.getSalt(), startsWith(SHA256_PREFIX)); | ||
assertThat(saltedPassword, is(notNullValue())); | ||
} | ||
|
||
|
@@ -31,6 +33,15 @@ public void testCreatingFromSaltedPassword() { | |
assertThat(saltedpassword.getSalt(), is(salt)); | ||
} | ||
|
||
@Test | ||
public void testCreateNewPasswordWithSaltFromOtherPassword() throws UnsupportedEncodingException { | ||
String plainpassword = "foo"; | ||
SaltedPassword storedPassword = new SaltedPassword(plainpassword); | ||
String saltFromStoredPassword = storedPassword.getSalt(); | ||
SaltedPassword givenPassword = new SaltedPassword(plainpassword, saltFromStoredPassword); | ||
assertTrue(storedPassword.equals(givenPassword)); | ||
} | ||
|
||
@Test | ||
public void testSaltedPasswordAsParts() throws UnsupportedEncodingException { | ||
SaltedPassword password = new SaltedPassword("foo"); | ||
|
@@ -46,6 +57,4 @@ public void testSaltedPasswordAsParts() throws UnsupportedEncodingException { | |
assertThat(parts[3], hasLength(43)); | ||
} | ||
|
||
|
||
|
||
} |