-
Notifications
You must be signed in to change notification settings - Fork 0
/
BcryptTest.cls
50 lines (43 loc) · 1.65 KB
/
BcryptTest.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@IsTest
public with sharing class BcryptTest {
@IsTest
public static void hashTest(){
String hash = Bcrypt.hash('hashing_password');
System.assert(Bcrypt.compare('hashing_password', hash), 'Password should match');
}
@IsTest
public static void hashFailedTest(){
String hash = Bcrypt.hash('hashing_password');
System.assert(!Bcrypt.compare('wrong_password', hash), 'Password should\'nt match');
}
@IsTest
public static void hashWithLessRoundsTest(){
String hash = Bcrypt.hash('hashing_password', 3);
System.assert(Bcrypt.compare('hashing_password', hash), 'Password should match');
}
@IsTest
public static void hashWithMoreRoundsTest(){
String hash = Bcrypt.hash('hashing_password', 32);
System.assert(Bcrypt.compare('hashing_password', hash), 'Password should match');
}
@IsTest
public static void wrongHashTest(){
try{
String hash = Bcrypt.hash('hashing_password', 'weirdhash');
System.assert(false, 'Should throw IllegalArgumentException');
}
catch(Exception e){
System.assert(e.getTypeName() == 'System.IllegalArgumentException', 'Should throw IllegalArgumentException');
}
}
@IsTest
public static void wrongHashLengthCompareTest(){
try{
Bcrypt.compare('hashing_password', 'weirdhash');
System.assert(false, 'Should throw IllegalArgumentException');
}
catch(Exception e){
System.assert(e.getTypeName() == 'System.IllegalArgumentException', 'Should throw IllegalArgumentException');
}
}
}