Skip to content

Commit

Permalink
Merge pull request #2026 from map-b/ELY-2697
Browse files Browse the repository at this point in the history
[ELY-2697] Update 4 tests in CompatibilityServerTest to call a common…
  • Loading branch information
fjuma authored Nov 8, 2023
2 parents cdb23f9 + a7b1beb commit 21c8315
Showing 1 changed file with 15 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@ public void testRfc2831example2() throws Exception {
assertEquals("chris", server.getAuthorizationID());
}


/**
* Test with authorization ID (authzid) of other user
*/
@Test
public void testUnauthorizedAuthorizationId() throws Exception {
private SaslServer testCommonInitSaslServer() throws Exception {
mockNonce("OA9BSXrbuRhWay");

Map<String, Object> serverProps = new HashMap<String, Object>();
Expand All @@ -159,6 +154,18 @@ public void testUnauthorizedAuthorizationId() throws Exception {
assertEquals("realm=\"elwood.innosoft.com\",nonce=\"OA9BSXrbuRhWay\",charset=utf-8,algorithm=md5-sess", new String(message1, "UTF-8"));
assertFalse(server.isComplete());

return server;
}


//********************************************** */
/**
* Test with authorization ID (authzid) of other user
*/
@Test
public void testUnauthorizedAuthorizationId() throws Exception {
SaslServer server = testCommonInitSaslServer();

byte[] message2 = "charset=utf-8,username=\"chris\",realm=\"elwood.innosoft.com\",nonce=\"OA9BSXrbuRhWay\",nc=00000001,cnonce=\"OA9BSuZWMSpW8m\",digest-uri=\"acap/elwood.innosoft.com\",maxbuf=65536,response=0d071450228e395e2c0999e02b6aa665,qop=auth,authzid=\"george\"".getBytes(StandardCharsets.UTF_8);

try {
Expand Down Expand Up @@ -560,22 +567,7 @@ public void testQopAuthConfRc440() throws Exception {
*/
@Test
public void testReplayAttack() throws Exception {
mockNonce("OA9BSXrbuRhWay");

Map<String, Object> serverProps = new HashMap<String, Object>();
serverProps.put(REALM_PROPERTY, "elwood.innosoft.com");
SaslServer server =
new SaslServerBuilder(DigestServerFactory.class, SaslMechanismInformation.Names.DIGEST_MD5)
.setUserName("chris")
.setPassword(ClearPassword.ALGORITHM_CLEAR, new ClearPasswordSpec("secret".toCharArray()))
.setProtocol("acap").setServerName("elwood.innosoft.com")
.setProperties(serverProps)
.build();
assertFalse(server.isComplete());

byte[] message1 = server.evaluateResponse(new byte[0]);
assertEquals("realm=\"elwood.innosoft.com\",nonce=\"OA9BSXrbuRhWay\",charset=utf-8,algorithm=md5-sess", new String(message1, "UTF-8"));
assertFalse(server.isComplete());
SaslServer server = testCommonInitSaslServer();

byte[] message2 = "charset=utf-8,username=\"chris\",realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",nc=00000001,cnonce=\"OA6MHXh6VqTrRk\",digest-uri=\"imap/elwood.innosoft.com\",response=d388dad90d4bbd760a152321f2143af7,qop=auth".getBytes(StandardCharsets.UTF_8);
try{
Expand All @@ -591,22 +583,7 @@ public void testReplayAttack() throws Exception {
*/
@Test
public void testBadResponse() throws Exception {
mockNonce("OA9BSXrbuRhWay");

Map<String, Object> serverProps = new HashMap<String, Object>();
serverProps.put(REALM_PROPERTY, "elwood.innosoft.com");
SaslServer server =
new SaslServerBuilder(DigestServerFactory.class, SaslMechanismInformation.Names.DIGEST_MD5)
.setUserName("chris")
.setPassword(ClearPassword.ALGORITHM_CLEAR, new ClearPasswordSpec("secret".toCharArray()))
.setProtocol("acap").setServerName("elwood.innosoft.com")
.setProperties(serverProps)
.build();
assertFalse(server.isComplete());

byte[] message1 = server.evaluateResponse(new byte[0]);
assertEquals("realm=\"elwood.innosoft.com\",nonce=\"OA9BSXrbuRhWay\",charset=utf-8,algorithm=md5-sess", new String(message1, "UTF-8"));
assertFalse(server.isComplete());
SaslServer server = testCommonInitSaslServer();

byte[] message2 = "charset=utf-8,username=\"chris\",realm=\"elwood.innosoft.com\",nonce=\"OA9BSXrbuRhWay\",nc=00000001,cnonce=\"OA9BSuZWMSpW8m\",digest-uri=\"acap/elwood.innosoft.com\",response=d388dad90d4bbd760a152321f2143af7,qop=auth".getBytes(StandardCharsets.UTF_8);
try{
Expand Down

0 comments on commit 21c8315

Please sign in to comment.