Skip to content

Commit

Permalink
Merge pull request #2034 from ericrleung/ELY-2683
Browse files Browse the repository at this point in the history
[ELY-2683] Refactor OAuth2SaslClientV11Test to use common method
Skyllarr authored Nov 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents c8f40d8 + 89344fc commit cdb23f9
Showing 1 changed file with 9 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -414,10 +414,8 @@ public void testWithResourceOwnerCredentialsInCredentialStoreUsingConfiguration(
testWithSaslClientAndServer("protocol://test8.org");
}

@Test
public void failedResourceOwnerCredentialsUsingConfiguration() throws Exception {
SaslClient saslClient = createSaslClientFromConfiguration(URI.create("protocol://test9.org"));

public void testInvalidCredentialsUsingConfiguration(String serverURI) throws Exception {
SaslClient saslClient = createSaslClientFromConfiguration(URI.create(serverURI));
assertNotNull("OAuth2SaslClient is null", saslClient);

SaslServer saslServer = new SaslServerBuilder(OAuth2SaslServerFactory.class, SaslMechanismInformation.Names.OAUTHBEARER)
@@ -442,57 +440,18 @@ public void failedResourceOwnerCredentialsUsingConfiguration() throws Exception
}

@Test
public void failedResourceOwnerCredentialsFromCredentialStoreUsingConfiguration() throws Exception {
SaslClient saslClient = createSaslClientFromConfiguration(URI.create("protocol://test10.org"));

assertNotNull("OAuth2SaslClient is null", saslClient);

SaslServer saslServer = new SaslServerBuilder(OAuth2SaslServerFactory.class, SaslMechanismInformation.Names.OAUTHBEARER)
.setServerName("resourceserver.comn")
.setProtocol("imap")
.addRealm("oauth-realm", createSecurityRealmMock())
.setDefaultRealmName("oauth-realm")
.build();

byte[] message = AbstractSaslParticipant.NO_BYTES;
public void failedResourceOwnerCredentialsUsingConfiguration() throws Exception {
testInvalidCredentialsUsingConfiguration("protocol://test9.org");
}

try {
do {
message = saslClient.evaluateChallenge(message);
if (message == null) break;
message = saslServer.evaluateResponse(message);
} while (message != null);
fail("Expected bad response from server");
} catch (Exception e) {
e.printStackTrace();
}
@Test
public void failedResourceOwnerCredentialsFromCredentialStoreUsingConfiguration() throws Exception {
testInvalidCredentialsUsingConfiguration("protocol://test10.org");
}

@Test
public void failedClientCredentialsFromCredentialStoreUsingConfiguration() throws Exception {
SaslClient saslClient = createSaslClientFromConfiguration(URI.create("protocol://test11.org"));

assertNotNull("OAuth2SaslClient is null", saslClient);

SaslServer saslServer = new SaslServerBuilder(OAuth2SaslServerFactory.class, SaslMechanismInformation.Names.OAUTHBEARER)
.setServerName("resourceserver.comn")
.setProtocol("imap")
.addRealm("oauth-realm", createSecurityRealmMock())
.setDefaultRealmName("oauth-realm")
.build();

byte[] message = AbstractSaslParticipant.NO_BYTES;

try {
do {
message = saslClient.evaluateChallenge(message);
if (message == null) break;
message = saslServer.evaluateResponse(message);
} while (message != null);
fail("Expected bad response from server");
} catch (Exception e) {
e.printStackTrace();
}
testInvalidCredentialsUsingConfiguration("protocol://test11.org");
}

private SecurityRealm createSecurityRealmMock() throws MalformedURLException {

0 comments on commit cdb23f9

Please sign in to comment.