예제 #1
0
def test_user_get(valid_session_credentials, valid_new_normal_user):
    """@pylatest api/user.get
    API-users: get user
    *******************

    .. test_metadata:: author [email protected] [email protected] [email protected]

    Description
    ===========

    Get user from ``valid_new_normal_user`` fixture.
    """
    test = tendrlapi_user.ApiUser(auth=valid_session_credentials)
    """@pylatest api/user.get
    .. test_step:: 2

        Send **GET** request to ``APIURL/users``.

    .. test_result:: 2

        List of users in database is returned
    """
    test.get_users()
    """@pylatest api/user.get
    .. test_step:: 3

        Get user info.

        Send **GET** request to ``APIURL/users/{user}``.

    .. test_result:: 3

        User information for user from ``valid_new_normal_user`` fixture is returned.
    """
    test.check_user(valid_new_normal_user)
예제 #2
0
def test_user_creation_password_invalid(application, valid_session_credentials,
                                        valid_normal_user_data,
                                        invalid_password):
    """
    Attempt to create a user with an invalid password.
    """
    """
    :step:
      Attempt to add user with invalid password.
    :result:
      User is not created.
    """
    user = application.collections.users.create(
        user_id=valid_normal_user_data["username"],
        name=valid_normal_user_data["name"],
        email=valid_normal_user_data["email"],
        notifications_on=valid_normal_user_data["email_notifications"],
        password=invalid_password,
        role=valid_normal_user_data["role"])
    pytest.check(not user.exists,
                 "Check that new user can't be found on UI Users page")
    """
    :step:
      Check that user hasn't been created using API
    :result:
      There's no user with the specified username
    """
    test = tendrlapi_user.ApiUser(auth=valid_session_credentials)
    user_data_password_invalid = copy.deepcopy(valid_normal_user_data)
    user_data_password_invalid["password"] = invalid_password
    asserts = {"ok": False, "reason": 'Not Found', "status": 404}
    not_found = test.get_user(user_data_password_invalid["username"],
                              asserts_in=asserts)
    pytest.check("Not found" in str(not_found),
                 "Check that new user can't be found using API")
예제 #3
0
def test_mysettings_alerting_switch(application, receive_alerts,
                                    valid_session_credentials):
    """
    Test switching alerts on and off in My Settings.
    """
    """
    :step:
      Change alert settings in My Settings (and password as well due to BZ1654623)
    :result:
    """
    admin_data = {
        "email": "root@" + CONF.inventory.get_groups_dict()["usm_client"][0],
        "password": CONF.config["usmqe"]["password"],
        "confirm_password": CONF.config["usmqe"]["password"],
        "notifications_on": receive_alerts
    }
    application.collections.users.edit_logged_in_user(admin_data)
    """
    :step:
      Check that alert settings changed
    :result:
    """
    test = tendrlapi_user.ApiUser(auth=valid_session_credentials)
    admin_data = {
        "name": "Admin",
        "username": "******",
        "email": "root@" + CONF.inventory.get_groups_dict()["usm_client"][0],
        "role": "admin",
        "email_notifications": receive_alerts
    }
    time.sleep(2)
    test.check_user(admin_data)
예제 #4
0
def valid_new_user(valid_user_data):
    """
    Create user from valid_user_data fixture and return these data.
    At the end remove this user.
    """
    auth = login(pytest.config.getini("usm_username"),
                 pytest.config.getini("usm_password"))
    admin = tendrlapi_user.ApiUser(auth=auth)
    admin.add_user(valid_user_data)
    yield valid_user_data
    admin.del_user(valid_user_data["username"])
    logout(auth=auth)
예제 #5
0
def delete_new_user(user_data):
    """
    Delete user with given user_data.
    """
    auth = login(pytest.config.getini("usm_username"),
                 pytest.config.getini("usm_password"))
    admin = tendrlapi_user.ApiUser(auth=auth)
    if user_data['email'].endswith(
            usmqe.inventory.role2hosts("usm_client")[0]):
        SSH = usmssh.get_ssh()
        node_connection = SSH[usmqe.inventory.role2hosts("usm_client")[0]]
        userdel = 'userdel {}'.format(user_data['username'])
        userdel_response = node_connection.run(userdel)
        # userdel command returned 0 return code
        assert userdel_response[0] == 0
    admin.del_user(user_data["username"])
    logout(auth=auth)
예제 #6
0
def delete_new_user(user_data):
    """
    Delete user with given user_data.
    """
    auth = login(CONF.config["usmqe"]["username"],
                 CONF.config["usmqe"]["password"])
    admin = tendrlapi_user.ApiUser(auth=auth)
    if user_data['email'].endswith(
            CONF.inventory.get_groups_dict()["usm_client"][0]):
        SSH = usmssh.get_ssh()
        node_connection = SSH[CONF.inventory.get_groups_dict()["usm_client"]
                              [0]]
        userdel = 'userdel {}'.format(user_data['username'])
        userdel_response = node_connection.run(userdel)
        # userdel command returned 0 return code
        assert userdel_response[0] == 0
    admin.del_user(user_data["username"])
    logout(auth=auth)
예제 #7
0
def create_new_user(user_data):
    """
    Create user from given user_data.
    """
    auth = login(pytest.config.getini("usm_username"),
                 pytest.config.getini("usm_password"))
    admin = tendrlapi_user.ApiUser(auth=auth)
    admin.add_user(user_data)

    if user_data['email'].endswith(
            usmqe.inventory.role2hosts("usm_client")[0]):
        SSH = usmssh.get_ssh()
        useradd = 'useradd {}'.format(user_data['username'])
        node_connection = SSH[usmqe.inventory.role2hosts("usm_client")[0]]
        node_connection.run(useradd)
        passwd = 'echo "{}" | passwd --stdin {}'.format(
            user_data['password'], user_data['username'])
        passwd_response = node_connection.run(passwd)
        # passwd command returned 0 return code
        assert passwd_response[0] == 0
예제 #8
0
def create_new_user(user_data):
    """
    Create user from given user_data.
    """
    auth = login(CONF.config["usmqe"]["username"],
                 CONF.config["usmqe"]["password"])
    admin = tendrlapi_user.ApiUser(auth=auth)
    admin.add_user(user_data)

    if user_data['email'].endswith(
            CONF.inventory.get_groups_dict()["usm_client"][0]):
        SSH = usmssh.get_ssh()
        useradd = 'useradd {}'.format(user_data['username'])
        node_connection = SSH[CONF.inventory.get_groups_dict()["usm_client"]
                              [0]]
        node_connection.run(useradd)
        passwd = 'echo "{}" | passwd --stdin {}'.format(
            user_data['password'], user_data['username'])
        passwd_response = node_connection.run(passwd)
        # passwd command returned 0 return code
        assert passwd_response[0] == 0
예제 #9
0
def test_delete_admin(valid_session_credentials):
    """@pylatest api/user.add_delete
    API-users: add and delete
    *************************

    .. test_metadata:: author [email protected]

    Description
    ===========

    Attempt to delete the admin user
    """
    test = tendrlapi_user.ApiUser(auth=valid_session_credentials)
    """@pylatest api/user.add_delete
    .. test_step:: 1

        Attempt to delete the admin user

    .. test_result:: 1

        Admin user is not deleted.

    """
    asserts = {"ok": False, "reason": 'Forbidden', "status": 403}

    test.del_user("admin", asserts_in=asserts)
    """@pylatest api/user.get
     .. test_step:: 2

         Check if user admin still exists

     .. test_result:: 2

         User admin still exists.

    """
    pytest.check(test.get_user("admin")["name"] == "Admin")
예제 #10
0
def test_user_change_password(valid_new_normal_user, valid_password):
    """@pylatest api/user.edit
    API-users: edit user
    *******************

    .. test_metadata:: author [email protected]

    Description
    ===========

    Change password and email of user and login with new password.
    """
    auth = login(valid_new_normal_user["username"],
                 valid_new_normal_user["password"])
    test = tendrlapi_user.ApiUser(auth=auth)
    """@pylatest api/user.get
    .. test_step:: 1

        Send **PUT** request to ``APIURL/users``.

        During this step is set email to `[email protected]` because
        user can not be edited if he does not have set email. (e.g. admin)

    .. test_result:: 1

        Edited user data are returned.
    """
    new_email = "*****@*****.**"
    edit_data = {
        "email": new_email,
        "password": valid_password,
        "password_confirmation": valid_password
    }
    test.edit_user(valid_new_normal_user["username"], edit_data)
    """@pylatest api/user.get
    .. test_step:: 2

        Login

        Send **POST** request to ``APIURL/login``.

    .. test_result:: 2

        User is logged with new credentials.
    """
    logout(auth=auth)
    auth = login(valid_new_normal_user["username"], valid_password)
    test = tendrlapi_user.ApiUser(auth=auth)
    """@pylatest api/user.get
    .. test_step:: 3

        Check if user have edited email.

        Send **GET** request to ``APIURL/users/{user}``.

    .. test_result:: 3

        User information is checked if email was correctly changed.
    """
    valid_new_normal_user["email"] = new_email
    test.check_user(valid_new_normal_user)
    logout(auth=auth)
예제 #11
0
def test_user_add_del(valid_session_credentials, valid_normal_user_data):
    """@pylatest api/user.add_delete
    API-users: add and delete
    *************************

    .. test_metadata:: author [email protected] [email protected] [email protected]

    Description
    ===========

    Add and remove *test* user.
    """
    test = tendrlapi_user.ApiUser(auth=valid_session_credentials)
    """@pylatest api/user.add_delete
    .. test_step:: 2

        Add user test2.

        Send **PUT** request to ``APIURL/users/test2`` with data from fixture
        valid_normal_user_data where are specified keys: email, username, name, role

    .. test_result:: 2

        User should be created.

        Return code should be 201.
    """
    # add test user

    added_user = test.add_user(valid_normal_user_data)
    """@pylatest api/user.add_delete
    .. test_step:: 3
       :include: api/user.get:2

    .. test_result:: 3
       :include: api/user.get:2
    """
    test.check_user(added_user)
    """@pylatest api/user.add_delete
    .. test_step:: 4

        Delete user test2.

        Send **DELETE** request to ``APIURL/users/test2``.

    .. test_result:: 4

        User test2 should be deleted.

        Return code should be 200.
    """
    test.del_user(valid_normal_user_data["username"])
    """@pylatest api/user.add_delete
    .. test_step:: 5
       :include: api/user.get:2

    .. test_result:: 5

        User test2 is not available.

        Return code should be 404.
    """
    asserts = {
        "json": json.loads('{"Error": "Not found"}'),
        "cookies": None,
        "ok": False,
        "reason": 'Not Found',
        "status": 404
    }
    test.get_user(valid_normal_user_data["username"], asserts_in=asserts)
    """@pylatest api/user.add_delete
예제 #12
0
def test_user_change_password_to_invalid(valid_new_normal_user,
                                         invalid_password):
    """@pylatest api/user.edit
    API-users: edit user
    *******************

    .. test_metadata:: author [email protected]

    Description
    ===========

    Attempt to change password to invalid - either too long or too short.
    Checks on 8-symbol password and on an extremely long password fail due to bug
    https://bugzilla.redhat.com/show_bug.cgi?id=1610947
    """
    auth = login(valid_new_normal_user["username"],
                 valid_new_normal_user["password"])
    test = tendrlapi_user.ApiUser(auth=auth)
    """@pylatest api/user.get
    .. test_step:: 1

        Send **PUT** request to ``APIURL/users``.

        During this step is set email to `[email protected]` because
        user can not be edited if he does not have set email. (e.g. admin)

    .. test_result:: 1

        Error 422 Unprocessable Entity is returned. The response includes words
        "is too long" or "is too short" depending on the invalid password length.
        This check might fail due to https://bugzilla.redhat.com/show_bug.cgi?id=1610947
    """
    new_email = "*****@*****.**"
    edit_data = {
        "email": new_email,
        "password": invalid_password,
        "password_confirmation": invalid_password
    }
    asserts = {"ok": False, "reason": 'Unprocessable Entity', "status": 422}

    response = test.edit_user(valid_new_normal_user["username"],
                              edit_data,
                              asserts_in=asserts)
    if len(invalid_password) > 10:
        pass_length_error = "is too long" in str(response)
    else:
        pass_length_error = "is too short" in str(response)
    pytest.check(pass_length_error,
                 issue='https://bugzilla.redhat.com/show_bug.cgi?id=1610947')
    """@pylatest api/user.get
    .. test_step:: 2

        Check if the response to the request in test_step 1 returned the expected error.
        If it didn't, change the password back to original.

    .. test_result:: 2

        User password is the same as it was before test_step 1

    """
    if not pass_length_error:
        edit_back_data = {
            "email": new_email,
            "password": valid_new_normal_user["password"],
            "password_confirmation": valid_new_normal_user["password"]
        }
        test.edit_user(valid_new_normal_user["username"], edit_back_data)
예제 #13
0
def test_user_crud(application, role, valid_session_credentials):
    """
    Create, edit and delete normal and limited user.
    """
    """
    :step:
      Create user
    :result:
      User is created
    """
    user = application.collections.users.create(
        user_id="{}_user_auto".format(role),
        name="{} user".format(role),
        email="{}[email protected]".format(role),
        notifications_on=False,
        password="******",
        role=role)
    pytest.check(user.exists,
                 "Check that new user can be found on UI Users page")
    test = tendrlapi_user.ApiUser(auth=valid_session_credentials)
    user_data = {
        "name": user.name,
        "username": user.user_id,
        "email": user.email,
        "role": user.role,
        "email_notifications": user.notifications_on
    }

    test.check_user(user_data)
    """
    :step:
      Edit user's email address and notification settings
    :result:
      User is edited
    """
    user.edit({
        "user_id": user.user_id,
        "name": user.name,
        "email": "edited_email_for_{}@example.com".format(role),
        "password": user.password,
        "confirm_password": user.password,
        "notifications_on": True
    })
    pytest.check(user.exists,
                 "Check that edited user can be found on UI Users page")
    pytest.check(user.email == "edited_email_for_{}@example.com".format(role),
                 "Check that user's e-mail has been edited")
    pytest.check(user.notifications_on,
                 "Check that user's notification settings have been edited")
    user_data["email"] = "edited_email_for_{}@example.com".format(role)
    user_data["email_notifications"] = True
    test.check_user(user_data)
    """
    :step:
      Log in as the edited user
    :result:
      User can log in
    """
    url = urlparse(CONF.config["usmqe"]["web_url"])
    app2 = Application(hostname=url.hostname,
                       scheme=url.scheme,
                       username=user.user_id,
                       password=user.password)
    ViaWebUI.navigate_to(app2.web_ui, "LoggedIn")
    app2.web_ui.browser_manager.quit()
    """
    :step:
      Delete user
    :result:
      User is deleted
    """
    user.delete()
    pytest.check(not user.exists,
                 "Check that user can't be found on UI Users page anymore.")
예제 #14
0
def test_add_user_invalid_username(valid_session_credentials,
                                   valid_normal_user_data, invalid_username):
    """@pylatest api/user.add_delete
    API-users: add and delete
    *************************

    .. test_metadata:: author [email protected]

    Description
    ===========

    Attempt to add a user with invalid username
    """
    test = tendrlapi_user.ApiUser(auth=valid_session_credentials)
    """@pylatest
    .. test_step:: 1 api/user.add_delete

        Attempt to add user using an invalid username, either too long or too short.

        Send **POST** request to ``APIURL/users`` with data from fixture
        valid_normal_user_data with valid username substituted with an invalid one

    .. test_result:: 1

        User should not be created.

        Return code should be 422.

        This check might fail due to https://bugzilla.redhat.com/show_bug.cgi?id=1610947
    """
    user_data_username_invalid = copy.deepcopy(valid_normal_user_data)
    user_data_username_invalid["username"] = invalid_username
    asserts = {"ok": False, "reason": 'Unprocessable Entity', "status": 422}
    test.add_user(user_data_username_invalid, asserts_in=asserts)
    """@pylatest api/user.get
    .. test_step:: 2

        Check that the user doesn't exist

    .. test_result:: 2

        User can not be found.

        Return code should be 404.

        This check might fail due to https://bugzilla.redhat.com/show_bug.cgi?id=1610947

    """
    asserts = {"ok": False, "reason": 'Not Found', "status": 404}
    not_found = test.get_user(user_data_username_invalid["username"],
                              asserts_in=asserts)
    """@pylatest api/user.add_delete
    .. test_step:: 3

        If the user was found, the user is deleted

    .. test_result:: 3

        If a new user was created during step 1 the user is deleted.

    """
    if "Not found" not in str(not_found):
        test.del_user(user_data_username_invalid["username"])