test/org/ohmage/test/auth/AuthenticationApiTest.java
private void testAuthentication(
			final String username, final String password) 
			throws ApiException {

		// No username.
		try {
			api.getHashedPassword(null, password, Controller.CLIENT);
			throw new IllegalStateException("Failed: No username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		
		// Invalid username.
		try {
			api.getHashedPassword("blah", password, Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		
		// No password.
		try {
			api.getHashedPassword(username, null, Controller.CLIENT);
			throw new IllegalStateException("Failed: No password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		
		// Invalid password.
		try {
			api.getHashedPassword(username, "blah", Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		
		// No client.
		try {
			api.getHashedPassword(username, password, null);
			throw new IllegalStateException("Failed: No client.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.SERVER_INVALID_CLIENT.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No client: " + ErrorCode.SERVER_INVALID_CLIENT, e);
			}
		}
		
		// This request should be valid.
		try {
			api.getHashedPassword(username, password, Controller.CLIENT);
		}
		catch(RequestErrorException e) {
			throw new IllegalStateException("Failed: Valid request.", e);
		}
	}
/**
	 * Tests the different possibilities for getting an user's hashed password.
	 * 
	 * @throws ApiException Thrown if there is a bug in the library.
	 * 
	 * @throws IllegalStateException Thrown if the test fails.
	 */
Tests the different possibilities for getting an user's hashed password.

@throws ApiException Thrown if there is a bug in the library.

@throws IllegalStateException Thrown if the test fails.
Tests the different possibilities for getting an user ' s hashed password . @throws ApiException Thrown if there is a bug in the library . @throws IllegalStateException Thrown if the test fails .
private void testAuthentication(
			final String username, final String password) 
			throws ApiException {
		try {
			api.getHashedPassword(null, password, Controller.CLIENT);
			throw new IllegalStateException("Failed: No username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getHashedPassword("blah", password, Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getHashedPassword(username, null, Controller.CLIENT);
			throw new IllegalStateException("Failed: No password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getHashedPassword(username, "blah", Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getHashedPassword(username, password, null);
			throw new IllegalStateException("Failed: No client.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.SERVER_INVALID_CLIENT.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No client: " + ErrorCode.SERVER_INVALID_CLIENT, e);
			}
		}
		try {
			api.getHashedPassword(username, password, Controller.CLIENT);
		}
		catch(RequestErrorException e) {
			throw new IllegalStateException("Failed: Valid request.", e);
		}
	}
private void testAuthentication ( final String username , final String password ) throws ApiException { try { api . getHashedPassword ( null , password , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: No username." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: No username: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getHashedPassword ( "blah" , password , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: Invalid username." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: Invalid username: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getHashedPassword ( username , null , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: No password." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: No password: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getHashedPassword ( username , "blah" , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: Invalid password." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: Invalid password: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getHashedPassword ( username , password , null ) ; throw new IllegalStateException ( "Failed: No client." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . SERVER_INVALID_CLIENT . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: No client: " + ErrorCode . SERVER_INVALID_CLIENT , e ) ; } } try { api . getHashedPassword ( username , password , Controller . CLIENT ) ; } catch ( RequestErrorException e ) { throw new IllegalStateException ( "Failed: Valid request." , e ) ; } }
Tests the different possibilities for getting an user's hashed password.
Tests the different possibilities for getting an user ' s hashed password .
// No username. // Invalid username. // No password. // Invalid password. // No client. // This request should be valid.