summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'test/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticatorTest.java')
-rw-r--r--test/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticatorTest.java107
1 files changed, 60 insertions, 47 deletions
diff --git a/test/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticatorTest.java b/test/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticatorTest.java
index 7217d8d..9969ebd 100644
--- a/test/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticatorTest.java
+++ b/test/com/isode/stroke/sasl/SCRAMSHA1ClientAuthenticatorTest.java
@@ -14,6 +14,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
+import com.isode.stroke.idn.IDNConverter;
+import com.isode.stroke.idn.ICUConverter;
+import com.isode.stroke.crypto.CryptoProvider;
+import com.isode.stroke.crypto.JavaCryptoProvider;
/**
*
@@ -21,107 +25,116 @@ import static org.junit.Assert.*;
*/
public class SCRAMSHA1ClientAuthenticatorTest {
+ private IDNConverter idnConverter;
+ private CryptoProvider crypto;
+
+ @Before
+ public void setUp() {
+ idnConverter = new ICUConverter();
+ crypto = new JavaCryptoProvider();
+ }
+
@Test
public void testGetInitialResponse() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("n,,n=user,r=abcdefghABCDEFGH"), response);
+ assertEquals(new SafeByteArray("n,,n=user,r=abcdefghABCDEFGH"), response);
}
@Test
public void testGetInitialResponse_UsernameHasSpecialChars() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH");
- testling.setCredentials(",us=,er=", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", false, idnConverter, crypto);
+ testling.setCredentials(",us=,er=", new SafeByteArray("pass"), "");
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("n,,n==2Cus=3D=2Cer=3D,r=abcdefghABCDEFGH"), response);
+ assertEquals(new SafeByteArray("n,,n==2Cus=3D=2Cer=3D,r=abcdefghABCDEFGH"), response);
}
@Test
public void testGetInitialResponse_WithAuthorizationID() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH");
- testling.setCredentials("user", "pass", "auth");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "auth");
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("n,a=auth,n=user,r=abcdefghABCDEFGH"), response);
+ assertEquals(new SafeByteArray("n,a=auth,n=user,r=abcdefghABCDEFGH"), response);
}
@Test
public void testGetInitialResponse_WithAuthorizationIDWithSpecialChars() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH");
- testling.setCredentials("user", "pass", "a=u,th");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "a=u,th");
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("n,a=a=3Du=2Cth,n=user,r=abcdefghABCDEFGH"), response);
+ assertEquals(new SafeByteArray("n,a=a=3Du=2Cth,n=user,r=abcdefghABCDEFGH"), response);
}
@Test
public void testGetInitialResponse_WithoutChannelBindingWithTLSChannelBindingData() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", false);
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", false, idnConverter, crypto);
testling.setTLSChannelBindingData(new ByteArray("xyza"));
- testling.setCredentials("user", "pass", "");
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("y,,n=user,r=abcdefghABCDEFGH"), response);
+ assertEquals(new SafeByteArray("y,,n=user,r=abcdefghABCDEFGH"), response);
}
@Test
public void testGetInitialResponse_WithChannelBindingWithTLSChannelBindingData() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", true);
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefghABCDEFGH", true, idnConverter, crypto);
testling.setTLSChannelBindingData(new ByteArray("xyza"));
- testling.setCredentials("user", "pass", "");
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("p=tls-unique,,n=user,r=abcdefghABCDEFGH"), response);
+ assertEquals(new SafeByteArray("p=tls-unique,,n=user,r=abcdefghABCDEFGH"), response);
}
@Test
public void testGetFinalResponse() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
assertTrue(testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=4096")));
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("c=biws,r=abcdefghABCDEFGH,p=CZbjGDpIteIJwQNBgO0P8pKkMGY="), response);
+ assertEquals(new SafeByteArray("c=biws,r=abcdefghABCDEFGH,p=CZbjGDpIteIJwQNBgO0P8pKkMGY="), response);
}
@Test
public void testGetFinalResponse_WithoutChannelBindingWithTLSChannelBindingData() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false);
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
testling.setTLSChannelBindingData(new ByteArray("xyza"));
testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=4096"));
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("c=eSws,r=abcdefghABCDEFGH,p=JNpsiFEcxZvNZ1+FFBBqrYvYxMk="), response);
+ assertEquals(new SafeByteArray("c=eSws,r=abcdefghABCDEFGH,p=JNpsiFEcxZvNZ1+FFBBqrYvYxMk="), response);
}
@Test
public void testGetFinalResponse_WithChannelBindingWithTLSChannelBindingData() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", true);
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", true, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
testling.setTLSChannelBindingData(new ByteArray("xyza"));
testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=4096"));
SafeByteArray response = testling.getResponse();
- assertEquals(new ByteArray("c=cD10bHMtdW5pcXVlLCx4eXph,r=abcdefghABCDEFGH,p=i6Rghite81P1ype8XxaVAa5l7v0="), response);
+ assertEquals(new SafeByteArray("c=cD10bHMtdW5pcXVlLCx4eXph,r=abcdefghABCDEFGH,p=i6Rghite81P1ype8XxaVAa5l7v0="), response);
}
@Test
public void testSetFinalChallenge() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=4096"));
boolean result = testling.setChallenge(new ByteArray("v=Dd+Q20knZs9jeeK0pi1Mx1Se+yo="));
@@ -131,8 +144,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetChallenge() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
boolean result = testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=4096"));
@@ -141,8 +154,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetChallenge_InvalidClientNonce() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
boolean result = testling.setChallenge(new ByteArray("r=abcdefgiABCDEFGH,s=MTIzNDU2NzgK,i=4096"));
@@ -151,8 +164,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetChallenge_OnlyClientNonce() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
boolean result = testling.setChallenge(new ByteArray("r=abcdefgh,s=MTIzNDU2NzgK,i=4096"));
@@ -161,8 +174,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetChallenge_InvalidIterations() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
boolean result = testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=bla"));
@@ -171,8 +184,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetChallenge_MissingIterations() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
boolean result = testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK"));
@@ -181,8 +194,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetChallenge_ZeroIterations() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
boolean result = testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=0"));
@@ -191,8 +204,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetChallenge_NegativeIterations() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
boolean result = testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=-1"));
@@ -201,8 +214,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testSetFinalChallenge_InvalidChallenge() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=4096"));
boolean result = testling.setChallenge(new ByteArray("v=e26kI69ICb6zosapLLxrER/631A="));
@@ -211,8 +224,8 @@ public class SCRAMSHA1ClientAuthenticatorTest {
@Test
public void testGetResponseAfterFinalChallenge() {
- SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh");
- testling.setCredentials("user", "pass", "");
+ SCRAMSHA1ClientAuthenticator testling = new SCRAMSHA1ClientAuthenticator("abcdefgh", false, idnConverter, crypto);
+ testling.setCredentials("user", new SafeByteArray("pass"), "");
testling.setChallenge(new ByteArray("r=abcdefghABCDEFGH,s=MTIzNDU2NzgK,i=4096"));
testling.setChallenge(new ByteArray("v=Dd+Q20knZs9jeeK0pi1Mx1Se+yo="));