def test_release_close_token_fail_not_locked(self): # Setup the tokens tokenManager = TokenManager() token = tokenManager.create_token('*****@*****.**') # Attempt to immediately release the token with self.assertRaises(Exception): tokenManager.release_close_token(token)
def test_get_user_for_token_pass(self): # Setup the tokens tokenManager = TokenManager() token = tokenManager.create_token('*****@*****.**') # Get the user user = tokenManager.get_user_for_token(token) self.assertEquals(user, '*****@*****.**')
def test_lock_on_token_fail_expired_token(self): # Setup the tokens tokenManager = TokenManager(1, 2) token = tokenManager.create_token('*****@*****.**') # Let the token expire time.sleep(3) # Lock the token with self.assertRaises(Exception): tokenManager.lock_on_token(token)
def test_lock_delete_user_pass(self): # Setup the tokens tokenManager = TokenManager() token1 = tokenManager.create_token('*****@*****.**') token2 = tokenManager.create_token('*****@*****.**') token3 = tokenManager.create_token('*****@*****.**') # Delete the User tokenManager.lock_on_token(token1) tokenManager.delete_user('*****@*****.**') # Verify the tokens were released with self.assertRaises(Exception): tokenManager.release_close_token(token)
def test_lock_release_close_token_pass(self): # Setup the tokens tokenManager = TokenManager() token = tokenManager.create_token('*****@*****.**') # Lock the token tokenManager.lock_on_token(token) # Release the token tokenManager.release_close_token(token) # Verify the token was released with self.assertRaises(Exception): tokenManager.release_close_token(token)
def test_lock_on_token_fail_inactive_token(self): # Setup and touch the token tokenManager = TokenManager(1, 60) token1 = tokenManager.create_token('*****@*****.**') tokenManager.lock_on_token(token1) token2 = tokenManager.release_update_token(token1) # Let the token go inactive for too long time.sleep(2) # Attempt to reacquire token with self.assertRaises(Exception): tokenManager.lock_on_token(token2)
def test_lock_release_update_token_pass(self): # Setup the tokens tokenManager = TokenManager() token1 = tokenManager.create_token('*****@*****.**') # Lock the first token tokenManager.lock_on_token(token1) # Release the first token token2 = tokenManager.release_update_token(token1) # Lock the second token tokenManager.lock_on_token(token2) # Release the second token token3 = tokenManager.release_update_token(token2) self.assertNotEquals(token1, token2) self.assertNotEquals(token2, token3)
# Main application loop # Validate args if len(sys.argv) < 6: print( 'Required Args: <host address> <host port> <sqlite file> <SSL key file> <SSL cert file>' ) exit() hostaddr = sys.argv[1] hostport = sys.argv[2] dbfile = sys.argv[3] keyfile = sys.argv[4] certfile = sys.argv[5] # Setup DB connection db = sqlite3.connect(dbfile) # Create necessary handler objects tokenManager = TokenManager() userManager = UserManager(db) requestHandler = RequestHandler(tokenManager, userManager) # Launch the server server = HTTPServer((hostaddr, int(hostport)), AuthServer) server.socket = ssl.wrap_socket(server.socket, keyfile=keyfile, certfile=certfile, server_side=True) server.serve_forever()
def test_release_close_token_fail_missing_token(self): tokenManager = TokenManager() with self.assertRaises(Exception): tokenManager.release_close_token('NotAValidToken')
def test_create_token_pass(self): tokenManager = TokenManager() token = tokenManager.create_token('*****@*****.**') self.assertTrue(token is not None) self.assertTrue(len(token) > 0)
def test_lock_on_token_fail_missing_token(self): tokenManager = TokenManager() with self.assertRaises(Exception): tokenManager.lock_on_token('*****@*****.**')
def test_get_user_for_token_fail_missing_token(self): tokenManager = TokenManager() with self.assertRaises(Exception): tokenManager.get_user_for_token('NotAValidToken')
def test_delete_user_fail_missing_user(self): tokenManager = TokenManager() with self.assertRaises(Exception): tokenManager.delete_user('NotAValidUser')