Skip to content
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

test: adding an integration test for the account deletion feature #8723

Merged
merged 54 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f665fcb
test: adding an integration test for the account deletion feature
albatrousse Jul 24, 2023
2334f42
add waiting time for account deletion to happen and typo fix in makef…
albatrousse Jul 25, 2023
b898e8e
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Jul 25, 2023
b7d5604
waiting tasks working but I deleted the module part (I will try later…
albatrousse Jul 26, 2023
871c2f2
checking if a user can log in with the deleted account ids
albatrousse Jul 26, 2023
bc4a2e5
make lint_perltidy
albatrousse Jul 26, 2023
c90a045
update of the make integration_test in order to start the minion docker
albatrousse Jul 26, 2023
db88fc1
updating how I detect when the delete user task is finished
albatrousse Jul 26, 2023
b9bf64d
make lint_perltidy
albatrousse Jul 26, 2023
aacc829
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Jul 26, 2023
1b74ff4
checking if the product has been anonymized
albatrousse Jul 27, 2023
bfea1e7
adding a sequence where the user sign out after its account has been …
albatrousse Jul 27, 2023
2af714f
readability
albatrousse Jul 27, 2023
f9c4a15
changing the way how I check if the product has been anonymized or not
albatrousse Jul 27, 2023
7927420
make lint_perltidy
albatrousse Jul 27, 2023
fa1b71a
increasing max waiting time of each job
albatrousse Jul 28, 2023
97fdf5e
importing $minion variable into APITest.pm
albatrousse Aug 2, 2023
1054e02
refactor $minion into a function get_minion() that returns the local …
albatrousse Aug 8, 2023
c6deba5
oups forgot one
albatrousse Aug 8, 2023
b224d78
typo
albatrousse Aug 8, 2023
cb97f47
perltidy
albatrousse Aug 8, 2023
6d28248
refactor get_minion in get_minion()
albatrousse Aug 11, 2023
05c3ed1
do not preload APITest in Apache/mod_perl: it should not be needed
stephanegigandet Aug 14, 2023
f506b10
adding a subprogram that waits the end of a given task and using it i…
albatrousse Aug 16, 2023
81c3de3
perltidy and changing the way I check if the product has been anonymized
albatrousse Aug 16, 2023
dec60c9
typo for perlcritic !
albatrousse Aug 16, 2023
a3ad65e
perltidy
albatrousse Aug 16, 2023
a26a5a6
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 16, 2023
0273178
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 17, 2023
42e91c3
removing unused variable
albatrousse Aug 17, 2023
c0738a6
perltidy
albatrousse Aug 17, 2023
c523365
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 17, 2023
4c37830
removing unused variable $words
albatrousse Aug 17, 2023
62163a5
returning a list of jobs instead of a job in get_minion_jobs
albatrousse Aug 17, 2023
5f4da7a
changing the way that I check if there are remaining jobs
albatrousse Aug 17, 2023
2c1991d
update of the doc
albatrousse Aug 17, 2023
b3cc6e4
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 17, 2023
e5a5dcf
trying to fix the fact that the waiting task can't catch the account …
albatrousse Aug 21, 2023
a61f4bc
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 21, 2023
c122273
perltidy
albatrousse Aug 21, 2023
94345ae
Merge branch 'albatrousse_delete_user_test' of https://github.com/ope…
albatrousse Aug 21, 2023
5f55ca3
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 21, 2023
26900d3
readding waiting task
albatrousse Aug 21, 2023
f8c9f1e
typo
albatrousse Aug 21, 2023
0fa7e5d
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 22, 2023
f05d5e9
reducing max_waiting time
albatrousse Aug 22, 2023
c5d9635
Merge branch 'albatrousse_delete_user_test' of https://github.com/ope…
albatrousse Aug 22, 2023
0659ebe
surely final commit : modification of get_minion_jobs
albatrousse Aug 22, 2023
60bb9f0
final commit : perltidy
albatrousse Aug 22, 2023
23cdf2a
real final commit : perlcritic
albatrousse Aug 22, 2023
d9f9f5a
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 23, 2023
3ab53f7
Merge branch 'main' into albatrousse_delete_user_test
albatrousse Aug 24, 2023
9dc1533
test: always use job object in get_minion_jobs
alexgarel Aug 31, 2023
92024f2
Merge branch 'main' into albatrousse_delete_user_test
alexgarel Aug 31, 2023
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ integration_test:
# we launch the server and run tests within same container
# we also need dynamicfront for some assets to exists
# this is the place where variables are important
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb backend dynamicfront incron
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion
# note: we need the -T option for ci (non tty environment)
${DOCKER_COMPOSE_TEST} exec -T backend prove -l -r tests/integration
${DOCKER_COMPOSE_TEST} stop
Expand All @@ -270,9 +270,9 @@ test-unit: guard-test
${DOCKER_COMPOSE_TEST} run --rm backend perl ${args} tests/unit/${test}

# usage: make test-int test=test-name.t
test-int: guard-test # usage: make test-one test=test-file.t
test-int: guard-test # usage: make test-int test=test-file.t
@echo "🥫 Running test: 'tests/integration/${test}' …"
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb backend dynamicfront incron
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion
${DOCKER_COMPOSE_TEST} exec backend perl ${args} tests/integration/${test}
# better shutdown, for if we do a modification of the code, we need a restart
${DOCKER_COMPOSE_TEST} stop backend
Expand Down
122 changes: 122 additions & 0 deletions tests/integration/delete_user.t
albatrousse marked this conversation as resolved.
Show resolved Hide resolved
alexgarel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/perl -w

use ProductOpener::PerlStandards;

use Test::More;
use ProductOpener::APITest qw/:all/;
use ProductOpener::Test qw/:all/;
use ProductOpener::TestDefaults qw/:all/;
use ProductOpener::Users qw/:all/;
use ProductOpener::Producers qw/:all/;
use ProductOpener::Producers qw/:all/;

remove_all_users();
wait_application_ready();

# new common user agent
my $ua = new_client();
my %create_client_args = (%default_user_form, (email => '[email protected]'));
create_user($ua, \%create_client_args);

# new admin user agent
my $admin = new_client();
create_user($admin, \%admin_user_form);

# common ua add a new product then delete the account while being still logged in
my %product_fields = (
code => '200000000098',
lang => "en",
product_name => "Cool test product 75ml",
generic_name => "A sample test product",
quantity => "75 ml",
link => "https://github.com/openfoodfacts/openfoodfacts-server",
expiration_date => "test",
ingredients_text => "apple, milk",
origin => "france",
serving_size => "10g",
packaging_text => "Plastic box, paper lid",
nutriment_salt_value => "1.1",
nutriment_salt_unit => "g",
);
edit_product($ua, \%product_fields);

my @words = (
albatrousse marked this conversation as resolved.
Show resolved Hide resolved
"Delete the user",
"User is being deleted. This may take a few minutes.",
"Invalid user.",
"Unknown user.",
"Incorrect user name or password."
);
my $url_userid = construct_test_url("/cgi/user.pl?type=edit&userid=tests", "world");
my $url_delete = construct_test_url("/cgi/user.pl", "world");
my $response_edit = $ua->get($url_userid);

my %delete_form = (
name => 'Test',
email => '[email protected]',
password => '',
confirm_password => '',
delete => 'on',
action => 'process',
type => 'edit',
userid => 'tests'
);

#checking if the delete button exist
like($response_edit->content, qr/\Q$words[0]\E/i, "the delete button does exist");

#deleting the account
my $before_delete_ts = time();
my $response_delete = $ua->post($url_delete, \%delete_form);
#checking if we are redirected to the account deleted page
like($response_delete->content, qr/\Q$words[1]\E/i, "the account was deleted");

#waiting the deletion task to be done
my $jobs = $minion->jobs({tasks => ["delete_user_task"]});
#iterate on job
while (my $job = $jobs->next) {
#only those who were created after the timestamp
my $waited = 0; #waiting time
if ($job->created > $before_delete_ts) {
#waiting the job to be done
while ($job->state == "inactive" or $job->state == "active" or $waited < 200) {
sleep(2);
$waited++;
}
}
}
#checking if there is still delete_user_task jobs
$jobs = $minion->jobs({tasks => ["delete_user_task"]});
my $jobs_count = 0;
while (my $job = $jobs->next) {
$jobs_count++;
}
ok($jobs_count == 0, "delete user task is finished");

# admin ua checking if the account is well deleted
my $response_userid = $admin->get($url_userid);

my $url_email = construct_test_url('/cgi/user.pl?type=edit&[email protected]', "world");
my $response_email = $admin->get($url_email);

my $url_contributor = construct_test_url("/contributor/tests", "world");
my $response_contributor = $admin->get($url_contributor);

#checking if the edit page of the common ua is well deleted
like($response_userid->content, qr/\Q$words[2]\E/i, "the userid edit page is well deleted");
#checking if the edit page of the common ua is well deleted
like($response_email->content, qr/\Q$words[2]\E/i, "the email edit page is well deleted");
#checking if the edit page of the common ua is well deleted
like($response_contributor->content, qr/\Q$words[3]\E/i, "the contributor page of the ua is well deleted");

# checking if an ua can reconnect with the deleted account ids
my $url_login = construct_test_url("/cgi/login.pl", "world");
my %login_form = (
user_id => "tests",
password => "testtest",
submit => "Sign in"
);
my $response_login = $ua->post($url_login, \%login_form);
like($response_login->content, qr/\Q$words[4]\E/i, "an user can't login with the deleted account ids");

done_testing();
Loading