Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

Commit

Permalink
test: add authenticator test (#1855)
Browse files Browse the repository at this point in the history
* add authenticator test for basic and session authenticator
* add empty session ID test
* add empty cookie test
  • Loading branch information
jayahariv committed Feb 6, 2019
1 parent 122159a commit a75efbb
Showing 1 changed file with 53 additions and 0 deletions.
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");
}
}

0 comments on commit a75efbb

Please sign in to comment.