def test_request_validator_master_password_missing(): """Tests the RequestValidator class with missing master password. Expects error thrown.""" request = create_mock_request(master_key='1234') dbclient = create_mock_dbclient() with pytest.raises(AssertionError): RequestValidator(request, dbclient).isValid()
def test_request_validator_correct_credentials(): """Tests the RequestValidator class with a valid request. Expects validation success and no error message.""" request = create_mock_request(master_password='******', master_key='1234') dbclient = create_mock_dbclient_with_master_collection(master_password='******', master_key='1234') RequestValidator(request, dbclient).isValid()
def test_update_request_validator_domain_missing(): """Tests the UpdateRequestValidator class with domain missing. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234') dbclient = create_mock_dbclient_with_master_collection( master_password='******', master_key='1234') valid, message = UpdateRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_DOMAIN_REQUIRED
def test_request_validator_incorrect_master_key(): """Tests the RequestValidator class with incorrect master password. Expects error thrown.""" request = create_mock_request(master_password='******', master_key='4321') dbclient = create_mock_dbclient_with_master_collection(master_password='******', master_key='1234') with pytest.raises(AssertionError): RequestValidator(request, dbclient).isValid()
def test_insert_request_validator_domain_missing(): """Tests the InsertRequestValidator class with missing domain. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', username='******', secret=['some_secret']) dbclient = create_mock_dbclient_with_master_collection(master_password='******', master_key='1234') valid, message = InsertRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_DOMAIN_REQUIRED
def test_update_request_validator_no_record_match(): """Tests the UpdateRequestValidator class with domain that doesn't exists in password manager collection. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', domain='some_domain') dbclient = create_mock_dbclient_with_master_and_password_manager_collection( master_password='******', master_key='1234', domain=None, username=None) valid, message = UpdateRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_SINGLE_RECORD_MATCH_REQUIRED_FOR_UPDATE
def test_update_request_validator_new_secrets_present_but_invalid(): """Tests the UpdateRequestValidator class with invalid secrets. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', domain='some_domain', new_secret=['some_Secret', None]) dbclient = create_mock_dbclient_with_master_collection( master_password='******', master_key='1234') valid, message = UpdateRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_NEW_SECRET_SPECIFIED_BUT_BLANK
def test_update_request_validator_new_username_present_but_empty(): """Tests the UpdateRequestValidator class with empty new username. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', domain='some_domain', new_username='') dbclient = create_mock_dbclient_with_master_collection( master_password='******', master_key='1234') valid, message = UpdateRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_NEW_USERNAME_SPECIFIED_BUT_BLANK
def test_query_request_validator_incorrect_query_type(): """Tests the QueryRequestValidator class with unacceptable query type. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', query_type='-1', domain='some_domain') dbclient = create_mock_dbclient_with_master_collection( master_password='******', master_key='1234') valid, message = QueryRequestValidator(request, dbclient, acceptable_query_type=[]).isValid() assert valid == False assert message == ERROR_QUERY_TYPE_REQUIRED
def test_insert_request_validator_valid_request(): """Tests the InsertRequestValidator class with valid request. Expects validation success and no error message.""" request = create_mock_request(master_password='******', master_key='1234', domain='some_domain', username='******', secret=['some_secret']) dbclient = create_mock_dbclient_with_master_and_password_manager_collection(master_password='******', master_key='1234', domain=None, username=None) valid, message = InsertRequestValidator(request, dbclient).isValid() assert valid == True assert message == None
def test_insert_request_validator_domain_username_already_exists(): """Tests the InsertRequestValidator class with domain and username already existing in password manager collection. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', domain='some_domain', username='******', secret=['some_secret']) dbclient = create_mock_dbclient_with_master_and_password_manager_collection(master_password='******', master_key='1234', domain='some_domain', username='******') valid, message = InsertRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_DUPLICATE_DOMAIN_USERNAME
def test_update_request_validator_same_old_and_new_username(): """Tests the UpdateRequestValidator class with same old and new username. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', domain='some_domain', new_username='******') dbclient = create_mock_dbclient_with_master_and_password_manager_collection( master_password='******', master_key='1234', domain='some_domain', username='******') valid, message = UpdateRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_OLD_AND_NEW_USERNAME_SAME
def test_update_request_validator_domain_and_new_username_already_exists(): """Tests the UpdateRequestValidator class with domain and new username combination already existing in the password manager collection. Expects validation failure and correct error message.""" request = create_mock_request(master_password='******', master_key='1234', domain='some_domain', new_username='******') dbclient = create_mock_dbclient_with_master_and_multiple_password_manager_collection( master_password='******', master_key='1234', domain1='some_domain', username1='some_username', domain2='some_domain', username2='some_new_username') valid, message = UpdateRequestValidator(request, dbclient).isValid() assert valid == False assert message == ERROR_DUPLICATE_DOMAIN_NEW_USERNAME
def test_query_request_validator_domain_missing(): """Tests the QueryRequestValidator class with domain missing. Expects validation failure and correct error message.""" request = create_mock_request( master_password='******', master_key='1234', query_type=QUERY_GET_SECRETS_FOR_DOMAIN_AND_USERNAME_TYPE) dbclient = create_mock_dbclient_with_master_collection( master_password='******', master_key='1234') valid, message = QueryRequestValidator( request, dbclient, acceptable_query_type=[ QUERY_GET_SECRETS_FOR_DOMAIN_AND_USERNAME_TYPE, QUERY_SEARCH_BY_DOMAIN_AND_USERNAME_TYPE ]).isValid() assert valid == False assert message == ERROR_DOMAIN_REQUIRED
def test_query_request_validator_valid_request(): """Tests the QueryRequestValidator class with valid request. Expects validation success and no error message.""" request = create_mock_request( master_password='******', master_key='1234', query_type=QUERY_GET_SECRETS_FOR_DOMAIN_AND_USERNAME_TYPE, domain='some_domain') dbclient = create_mock_dbclient_with_master_collection( master_password='******', master_key='1234') valid, message = QueryRequestValidator( request, dbclient, acceptable_query_type=[ QUERY_GET_SECRETS_FOR_DOMAIN_AND_USERNAME_TYPE, QUERY_SEARCH_BY_DOMAIN_AND_USERNAME_TYPE ]).isValid() assert valid == True assert message == None
def test_query_request_validator_username_present_but_empty(): """Tests the QueryRequestValidator class with empty username. Expects validation failure and correct error message.""" request = create_mock_request( master_password='******', master_key='1234', query_type=QUERY_GET_SECRETS_FOR_DOMAIN_AND_USERNAME_TYPE, domain='some_domain', username='') dbclient = create_mock_dbclient_with_master_collection( master_password='******', master_key='1234') valid, message = QueryRequestValidator( request, dbclient, acceptable_query_type=[ QUERY_GET_SECRETS_FOR_DOMAIN_AND_USERNAME_TYPE, QUERY_SEARCH_BY_DOMAIN_AND_USERNAME_TYPE ]).isValid() assert valid == False assert message == ERROR_USERNAME_SPECIFIED_BUT_BLANK