]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/passwords/TestPasswordHashChecker.java
add: test for PasswordHashChecker
[gigi.git] / tests / club / wpia / gigi / passwords / TestPasswordHashChecker.java
1 package club.wpia.gigi.passwords;
2
3 import java.io.IOException;
4 import java.nio.channels.FileChannel;
5 import java.nio.file.Files;
6 import java.nio.file.Path;
7 import java.nio.file.StandardOpenOption;
8 import java.nio.ByteBuffer;
9 import java.security.MessageDigest;
10 import java.security.NoSuchAlgorithmException;
11
12 import static org.junit.Assert.*;
13
14 import org.junit.Test;
15
16 import club.wpia.gigi.passwords.PasswordChecker;
17 import club.wpia.gigi.passwords.PasswordHashChecker;
18 import club.wpia.gigi.testUtils.ClientBusinessTest;
19
20 public class TestPasswordHashChecker extends ClientBusinessTest {
21
22     @Test
23     public void testPasswordHashes() throws IOException, NoSuchAlgorithmException {
24         Path tempPath = Files.createTempFile("hashes", ".bin");
25         FileChannel tempFile = FileChannel.open(tempPath, StandardOpenOption.READ, StandardOpenOption.WRITE);
26         tempFile.write(ByteBuffer.wrap(new byte[] { (byte)0x5b, (byte)0xaa, (byte)0x61, (byte)0xe4, (byte)0xc9, (byte)0xb9, (byte)0x3f, (byte)0x3f, (byte)0x06, (byte)0x82, (byte)0x25, (byte)0x0b, (byte)0x6c, (byte)0xf8, (byte)0x33, (byte)0x1b, (byte)0x7e, (byte)0xe6, (byte)0x8f, (byte)0xd8 })); // hash of "password"
27         tempFile.write(ByteBuffer.wrap(new byte[] { (byte)0x8b, (byte)0xe3, (byte)0xc9, (byte)0x43, (byte)0xb1, (byte)0x60, (byte)0x9f, (byte)0xff, (byte)0xbf, (byte)0xc5, (byte)0x1a, (byte)0xad, (byte)0x66, (byte)0x6d, (byte)0x0a, (byte)0x04, (byte)0xad, (byte)0xf8, (byte)0x3c, (byte)0x9d })); // hash of "Password"
28         tempFile.write(ByteBuffer.wrap(new byte[] { (byte)0xab, (byte)0xf7, (byte)0xaa, (byte)0xd6, (byte)0x43, (byte)0x88, (byte)0x36, (byte)0xdb, (byte)0xe5, (byte)0x26, (byte)0xaa, (byte)0x23, (byte)0x1a, (byte)0xbd, (byte)0xe2, (byte)0xd0, (byte)0xee, (byte)0xf7, (byte)0x4d, (byte)0x42 })); // hash of "correct horse battery staple"
29
30         PasswordChecker checker = new PasswordHashChecker(tempFile, MessageDigest.getInstance("SHA-1"));
31
32         assertNotNull(checker.checkPassword("password", new String[0], ""));
33         assertNotNull(checker.checkPassword("Password", new String[0], ""));
34         assertNotNull(checker.checkPassword("correct horse battery staple", new String[0], ""));
35         assertNull(checker.checkPassword("Correct Horse Battery Staple", new String[0], ""));
36     }
37
38 }