Exemple #1
0
def test_requests_close_unauthorized(client: TestClient, maintainer: User,
                                     pkgreq: PackageRequest):
    cookies = {"AURSID": maintainer.login(Request(), "testPassword")}
    with client as request:
        resp = request.get(f"/requests/{pkgreq.ID}/close",
                           cookies=cookies,
                           allow_redirects=False)
    assert resp.status_code == int(HTTPStatus.SEE_OTHER)
    assert resp.headers.get("location") == "/"
Exemple #2
0
def password(P: str = str(),
             request: Request = None,
             user: models.User = None,
             context: Dict[str, Any] = {},
             **kwargs) -> None:
    if P and not user.valid_password(P):
        # Remove the fields we consumed for passwords.
        context["P"] = context["C"] = str()

        # If a password was given and it doesn't match the user's, update it.
        with db.begin():
            user.update_password(P)

        if user == request.user:
            remember_me = request.cookies.get("AURREMEMBER", False)

            # If the target user is the request user, login with
            # the updated password to update the Session record.
            user.login(request, P, cookies.timeout(remember_me))
Exemple #3
0
def test_requests_close_post_rejected(client: TestClient, user: User,
                                      pkgreq: PackageRequest):
    cookies = {"AURSID": user.login(Request(), "testPassword")}
    with client as request:
        resp = request.post(f"/requests/{pkgreq.ID}/close",
                            cookies=cookies,
                            allow_redirects=False)
    assert resp.status_code == int(HTTPStatus.SEE_OTHER)

    assert pkgreq.Status == REJECTED_ID
    assert pkgreq.Closer == user
    assert pkgreq.ClosureComment == str()
Exemple #4
0
def test_suspended_ownership_change(user: User, pkgbases: List[PackageBase]):
    with db.begin():
        user.Suspended = 1

    pkgbase = pkgbases[0]
    notif = notify.ComaintainerAddNotification(user.ID, pkgbase.ID)
    notif.send()
    assert Email.count() == 1

    Email.reset()  # Clear the Email pool
    notif = notify.ComaintainerRemoveNotification(user.ID, pkgbase.ID)
    notif.send()
    assert Email.count() == 1
Exemple #5
0
def test_smtp(user: User):
    with db.begin():
        user.ResetKey = "12345678901234567890123456789012"

    smtp = FakeSMTP()

    get = "aurweb.config.get"
    getboolean = "aurweb.config.getboolean"
    with mock.patch(get, side_effect=mock_smtp_config(str)):
        with mock.patch(getboolean, side_effect=mock_smtp_config(bool)):
            with mock.patch("smtplib.SMTP", side_effect=smtp):
                config.rehash()
                notif = notify.WelcomeNotification(user.ID)
                notif.send()
    config.rehash()
    assert len(smtp.emails) == 1
Exemple #6
0
def test_requests_selfmade(client: TestClient, user: User,
                           requests: List[PackageRequest]):
    cookies = {"AURSID": user.login(Request(), "testPassword")}
    with client as request:
        resp = request.get("/requests", cookies=cookies)
    assert resp.status_code == int(HTTPStatus.OK)

    # As the user who creates all of the requests, we should see all of them.
    # However, we are not allowed to accept any of them ourselves.
    root = parse_root(resp.text)
    rows = root.xpath('//table[@class="results"]/tbody/tr')
    assert len(rows) == defaults.PP

    # Our first and only link in the last row should be "Close".
    for row in rows:
        last_row = row.xpath('./td')[-1].xpath('./a')[0]
        assert last_row.text.strip() == "Close"
Exemple #7
0
def test_welcome(user: User):
    with db.begin():
        user.ResetKey = "12345678901234567890123456789012"

    notif = notify.WelcomeNotification(user.ID)
    notif.send()
    assert Email.count() == 1

    email = Email(1).parse()
    expected = "Welcome to the Arch User Repository"
    assert email.headers.get("Subject") == expected

    expected = f"""\
Welcome to the Arch User Repository! In order to set an initial
password for your new account, please click the link [1] below. If the
link does not work, try copying and pasting it into your browser.

[1] {aur_location}/passreset/?resetkey=12345678901234567890123456789012\
"""
    assert email.body == expected
Exemple #8
0
def test_reset(user: User):
    with db.begin():
        user.ResetKey = "12345678901234567890123456789012"

    notif = notify.ResetKeyNotification(user.ID)
    notif.send()
    assert Email.count() == 1

    email = Email(1).parse()
    expected = "AUR Password Reset"
    assert email.headers.get("Subject") == expected

    expected = f"""\
A password reset request was submitted for the account test associated
with your email address. If you wish to reset your password follow the
link [1] below, otherwise ignore this message and nothing will happen.

[1] {aur_location}/passreset/?resetkey=12345678901234567890123456789012\
"""
    assert email.body == expected
Exemple #9
0
def test_requests(client: TestClient, tu_user: User, packages: List[Package],
                  requests: List[PackageRequest]):
    cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
    with client as request:
        resp = request.get(
            "/requests",
            params={
                # Pass in url query parameters O, SeB and SB to exercise
                # their paths inside of the pager_nav used in this request.
                "O": 0,  # Page 1
                "SeB": "nd",
                "SB": "n"
            },
            cookies=cookies)
    assert resp.status_code == int(HTTPStatus.OK)

    assert "Next ›" in resp.text
    assert "Last »" in resp.text

    root = parse_root(resp.text)
    # We have 55 requests, our defaults.PP is 50, so expect we have 50 rows.
    rows = root.xpath('//table[@class="results"]/tbody/tr')
    assert len(rows) == defaults.PP

    # Request page 2 of the requests page.
    with client as request:
        resp = request.get(
            "/requests",
            params={
                "O": 50  # Page 2
            },
            cookies=cookies)
    assert resp.status_code == int(HTTPStatus.OK)

    assert "‹ Previous" in resp.text
    assert "« First" in resp.text

    root = parse_root(resp.text)
    rows = root.xpath('//table[@class="results"]/tbody/tr')
    assert len(rows) == 5  # There are five records left on the second page.
Exemple #10
0
def account_type(T: int = None, user: models.User = None, **kwargs) -> None:
    if T is not None and (T := int(T)) != user.AccountTypeID:
        with db.begin():
            user.AccountTypeID = T
Exemple #11
0
def simple(U: str = str(),
           E: str = str(),
           H: bool = False,
           BE: str = str(),
           R: str = str(),
           HP: str = str(),
           I: str = str(),
           K: str = str(),
           J: bool = False,
           CN: bool = False,
           UN: bool = False,
           ON: bool = False,
           S: bool = False,
           user: models.User = None,
           **kwargs) -> None:
    now = time.utcnow()
    with db.begin():
        user.Username = U or user.Username
        user.Email = E or user.Email
        user.HideEmail = strtobool(H)
        user.BackupEmail = user.BackupEmail if BE is None else BE
        user.RealName = user.RealName if R is None else R
        user.Homepage = user.Homepage if HP is None else HP
        user.IRCNick = user.IRCNick if I is None else I
        user.PGPKey = user.PGPKey if K is None else K
        user.Suspended = strtobool(S)
        user.InactivityTS = now * int(strtobool(J))
        user.CommentNotify = strtobool(CN)
        user.UpdateNotify = strtobool(UN)
        user.OwnershipNotify = strtobool(ON)
Exemple #12
0
def auser2(user2: User) -> User:
    """ Yield an authenticated secondary non-maintainer User instance. """
    cookies = {"AURSID": user2.login(Request(), "testPassword")}
    user2.cookies = cookies
    yield user2
Exemple #13
0
def auser(user: User) -> User:
    """ Yield an authenticated User instance. """
    cookies = {"AURSID": user.login(Request(), "testPassword")}
    user.cookies = cookies
    yield user