This repository has been archived by the owner on Mar 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add authenticator test (#1855)
* add authenticator test for basic and session authenticator * add empty session ID test * add empty cookie test
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
android/CouchbaseLite/src/androidTest/java/com/couchbase/lite/AuthenticatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.couchbase.lite; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class AuthenticatorTest extends BaseTest { | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test | ||
public void testBasicAuthenticatorInstance() throws CouchbaseLiteException { | ||
String username = "someUsername"; | ||
String password = "somePassword"; | ||
BasicAuthenticator auth = new BasicAuthenticator(username, password); | ||
assertEquals(auth.getUsername(), username); | ||
assertEquals(auth.getPassword(), password); | ||
} | ||
|
||
@Test | ||
public void testSessionAuthenticatorWithSessionID() throws CouchbaseLiteException { | ||
String sessionID = "someSessionID"; | ||
SessionAuthenticator auth = new SessionAuthenticator(sessionID); | ||
assertEquals(auth.getSessionID(), sessionID); | ||
assertEquals(auth.getCookieName(), "SyncGatewaySession"); | ||
} | ||
|
||
@Test | ||
public void testSessionAuthenticatorWithSessionIDAndCookie() throws CouchbaseLiteException { | ||
String sessionID = "someSessionID"; | ||
String cookie = "someCookie"; | ||
SessionAuthenticator auth = new SessionAuthenticator(sessionID, cookie); | ||
assertEquals(auth.getSessionID(), sessionID); | ||
assertEquals(auth.getCookieName(), cookie); | ||
} | ||
|
||
@Test | ||
public void testSessionAuthenticatorEmptySessionID() throws CouchbaseLiteException { | ||
thrown.expect(IllegalArgumentException.class); | ||
SessionAuthenticator auth = new SessionAuthenticator(null, null); | ||
} | ||
|
||
@Test | ||
public void testSessionAuthenticatorEmptyCookie() throws CouchbaseLiteException { | ||
String sessionID = "someSessionID"; | ||
SessionAuthenticator auth = new SessionAuthenticator(sessionID, null); | ||
assertEquals(auth.getSessionID(), sessionID); | ||
assertEquals(auth.getCookieName(), "SyncGatewaySession"); | ||
} | ||
} |