Skip to content

debug #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 22, 2025
Merged

debug #193

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions resources/lib/UnitySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,18 @@ public function accDeletionRequestExists($uid)
return count($stmt->fetchAll()) > 0;
}

public function deleteAccountDeletionRequest($uid)
{
if (!$this->accDeletionRequestExists($uid)) {
return;
}
$stmt = $this->conn->prepare(
"DELETE FROM " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " WHERE uid=:uid"
);
$stmt->bindParam(":uid", $uid);
$stmt->execute();
}

public function getSiteVar($name)
{
$stmt = $this->conn->prepare(
Expand Down
40 changes: 25 additions & 15 deletions test/functional/AccountDeletionRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@ public function testRequestAccountDeletionUserHasNoGroups()
switchUser(...getUserHasNotRequestedAccountDeletionHasNoGroups());
$this->assertEmpty($USER->getGroups());
$this->assertNumberAccountDeletionRequests(0);
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "account_deletion_request"]
);
$this->assertNumberAccountDeletionRequests(1);
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "account_deletion_request"]
);
$this->assertNumberAccountDeletionRequests(1);
try {
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "account_deletion_request"]
);
$this->assertNumberAccountDeletionRequests(1);
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "account_deletion_request"]
);
$this->assertNumberAccountDeletionRequests(1);
} finally {
$SQL->deleteAccountDeletionRequest($USER->getUID());
$this->assertNumberAccountDeletionRequests(0);
}
}

public function testRequestAccountDeletionUserHasGroup()
Expand All @@ -56,10 +61,15 @@ public function testRequestAccountDeletionUserHasGroup()
switchUser(...getUserHasNotRequestedAccountDeletionHasGroup());
$this->assertNotEmpty($USER->getGroups());
$this->assertNumberAccountDeletionRequests(0);
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "account_deletion_request"]
);
$this->assertNumberAccountDeletionRequests(0);
try {
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "account_deletion_request"]
);
$this->assertNumberAccountDeletionRequests(0);
} finally {
$SQL->deleteAccountDeletionRequest($USER->getUID());
$this->assertNumberAccountDeletionRequests(0);
}
}
}
42 changes: 32 additions & 10 deletions test/functional/PiBecomeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,37 @@ public function testRequestBecomePi()
switchUser(...getUserNotPiNotRequestedBecomePi());
$this->assertFalse($USER->isPI());
$this->assertNumberPiBecomeRequests(0);
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "pi_request"]
);
$this->assertNumberPiBecomeRequests(1);
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "pi_request"]
);
$this->assertNumberPiBecomeRequests(1);
try {
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "pi_request"]
);
$this->assertNumberPiBecomeRequests(1);
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "pi_request"]
);
$this->assertNumberPiBecomeRequests(1);
} finally {
$SQL->removeRequest($USER->getUID());
}
}

public function testRequestBecomePiUserRequestedAccountDeletion()
{
global $USER, $SQL;
switchUser(...getUserNotPiNotRequestedBecomePiRequestedAccountDeletion());
$this->assertFalse($USER->isPI());
$this->assertNumberPiBecomeRequests(0);
$this->assertTrue($SQL->accDeletionRequestExists($USER->getUID()));
try {
post(
__DIR__ . "/../../webroot/panel/account.php",
["form_type" => "pi_request"]
);
$this->assertNumberPiBecomeRequests(0);
} finally {
$SQL->removeRequest($USER->getUID());
}
}
}
5 changes: 5 additions & 0 deletions test/phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ function getUserNotPiNotRequestedBecomePi()
{
return ["user2@org1.test", "foo", "bar", "user2@org1.test"];
}

function getUserNotPiNotRequestedBecomePiRequestedAccountDeletion()
{
return ["user4@org1.test", "foo", "bar", "user4@org1.test"];
}
4 changes: 3 additions & 1 deletion tools/docker-dev/sql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ RUN apt-get update && apt-get install -y \
netcat-openbsd
RUN sed -i '/bind-address/c\bind-address = 0.0.0.0' /etc/mysql/mariadb.conf.d/50-server.cnf
COPY bootstrap.sql /tmp/bootstrap.sql
COPY bootstrap-users.sql /tmp/bootstrap-users.sql

RUN service mariadb start; \
mariadb -e "CREATE DATABASE unity"; \
mariadb -e "CREATE USER 'unity'@'%' IDENTIFIED BY 'password'"; \
mariadb -e "GRANT ALL PRIVILEGES ON unity.* TO 'unity'@'%'"; \
mariadb -e "FLUSH PRIVILEGES"; \
mariadb unity < /tmp/bootstrap.sql
mariadb unity < /tmp/bootstrap.sql; \
mariadb unity < /tmp/bootstrap-users.sql

RUN rm -rf /tmp/bootstrap.sql

Expand Down
1 change: 1 addition & 0 deletions tools/docker-dev/sql/bootstrap-users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `account_deletion_requests` (`id`, `timestamp`, `uid`) VALUES (1, '1970-01-01 00:00:01', 'user4_org1_test');
Loading