Skip to content

Commit e1f155b

Browse files
committed
Polish SCrypt Upgrade Support
* Break up tests * Rename test methods to follow conventions * Fix checkstyle Issue gh-7057
1 parent e95effc commit e1f155b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

crypto/src/main/java/org/springframework/security/crypto/scrypt/SCryptPasswordEncoder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ public boolean upgradeEncoding(String encodedPassword) {
156156
return cpuCost < this.cpuCost
157157
|| memoryCost < this.memoryCost
158158
|| parallelization < this.parallelization;
159-
160159
}
161160

162161
private boolean decodeAndCheckMatches(CharSequence rawPassword, String encodedPassword) {

crypto/src/test/java/org/springframework/security/crypto/scrypt/SCryptPasswordEncoderTests.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,33 +117,48 @@ public void invalidKeyLengthParameter() {
117117
}
118118

119119
@Test
120-
public void upgradeEncoding_nullOrEmptyInput() {
120+
public void upgradeEncodingWhenNullThenFalse() {
121121
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
122122
assertThat(encoder.upgradeEncoding(null)).isFalse();
123+
}
124+
125+
@Test
126+
public void upgradeEncodingWhenEmptyThenFalse() {
127+
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
123128
assertThat(encoder.upgradeEncoding("")).isFalse();
124129
}
125130

126131
@Test
127-
public void upgradeEncoding_sameEncoder() {
132+
public void upgradeEncodingWhenSameEncoderThenFalse() {
128133
SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
129134
String encoded = encoder.encode("password");
130135
assertThat(encoder.upgradeEncoding(encoded)).isFalse();
131136
}
132137

133138
@Test
134-
public void upgradeEncoding_weakerToStronger() {
139+
public void upgradeEncodingWhenWeakerToStrongerThenFalse() {
135140
SCryptPasswordEncoder weakEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 10), 4, 1, 32, 64);
136141
SCryptPasswordEncoder strongEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 16), 8, 1, 32, 64);
137142

138143
String weakPassword = weakEncoder.encode("password");
139144
String strongPassword = strongEncoder.encode("password");
140145

141-
assertThat(strongEncoder.upgradeEncoding(weakPassword)).isTrue();
142146
assertThat(weakEncoder.upgradeEncoding(strongPassword)).isFalse();
143147
}
144148

149+
@Test
150+
public void upgradeEncodingWhenStrongerToWeakerThenTrue() {
151+
SCryptPasswordEncoder weakEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 10), 4, 1, 32, 64);
152+
SCryptPasswordEncoder strongEncoder = new SCryptPasswordEncoder((int) Math.pow(2, 16), 8, 1, 32, 64);
153+
154+
String weakPassword = weakEncoder.encode("password");
155+
String strongPassword = strongEncoder.encode("password");
156+
157+
assertThat(strongEncoder.upgradeEncoding(weakPassword)).isTrue();
158+
}
159+
145160
@Test(expected = IllegalArgumentException.class)
146-
public void upgradeEncoding_invalidInput() {
161+
public void upgradeEncodingWhenInvalidInputThenException() {
147162
new SCryptPasswordEncoder().upgradeEncoding("not-a-scrypt-password");
148163
}
149164
}

0 commit comments

Comments
 (0)