Skip to content
Merged
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
55 changes: 44 additions & 11 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Mailnesia Perl unittests
name: Mailnesia Perl tests

on:
push:
Expand All @@ -7,42 +7,75 @@ on:
branches: [master]

jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- name: checkout code
- name: Checkout code
uses: actions/checkout@v4
- name: set up Perl

- name: Set up Perl
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: "5.32"

- name: print working directory
run: pwd
- name: install dependencies
- name: Install dependencies
run: cpanm --installdeps . --skip-satisfied
- name: create tables in postgres
shell: bash

- name: Create tables in postgres
run: bash ./tools/psql-create-tables.sh
env:
postgres_host: localhost
postgres_user: mailnesia
PGPASSWORD: test
- name: execute unit/function tests
shell: bash

- name: Execute unit / function tests
run: prove -lv t
env:
postgres_host: localhost
postgres_user: mailnesia
postgres_password: test
redis_host: localhost

- name: Install swaks for email testing
run: sudo apt-get install -y swaks

- name: Execute e2e tests
uses: MohamedRaslan/background_run_and_test@v1
with:
start: |
morbo --listen http://*:3000 ./script/website-pages.pl
morbo --listen http://*:3001 ./script/website.pl
morbo --listen http://*:3002 ./script/api.pl
morbo --listen http://*:3003 ./script/rss.pl
perl ./script/clicker.pl
perl ./script/AnyEvent-SMTP-Server.pl -d

wait-on: |
http://localhost:3000
http://localhost:3001/mailbox/test
http://localhost:3002/api/mailbox/test
http://localhost:3003/rss/test
tcp:5000
tcp:2525
command: perl tools/test-mailnesia.pl --dont-start-smtp-server
env:
postgres_host: localhost
postgres_user: mailnesia
postgres_password: test
redis_host: localhost
website_pages_baseurl: http://localhost:3000
website_baseurl: http://localhost:3001
api_baseurl: http://localhost:3002
rss_baseurl: http://localhost:3003

# Service containers to start
services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# TODO: password?
#
ports:
# Opens tcp port 6379 on the host and service container
- 6379:6379
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,27 @@ upon save in Emacs.

## Testing

Test running website and mail server by sending test emails:
### End-to-end tests
#### Description
Test running website and mail server by sending test emails.

#### Requirements
All services must be running, as well as Postgres and Redis. Email sending
requires the `swaks` tool which can be installed with:

sudo apt-get install swaks -y

#### Execution

tools/test-mailnesia.pl

Execute function tests under t/ (these don't require the website to be up):
### Unit & function tests
#### Description
Execute function tests under t/.

#### Requirements
These don't require the website to be up, but running Postgres and Redis are necessary.

#### Execution

prove
18 changes: 6 additions & 12 deletions script/AnyEvent-SMTP-Server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ sub nextOne {
}
}

my $debugging_mode = 0;
if ($ARGV[0] and ($ARGV[0] eq '-d' or $ARGV[0] eq '--debug')) {
$debugging_mode = 1;
}

my $email_count=0;
my $email_bandwidth=0;

my $config = Mailnesia::Config->new;
my $config = Mailnesia::Config->new($debugging_mode);
my $mailnesia = Mailnesia->new;

#maximum size the clicker will download
Expand All @@ -87,7 +92,6 @@ sub nextOne {

#pid file:
my $pidfile = $config->{pidfile};
my $debugging_mode;

# do not save email / click logs
my $logging_disabled = 1;
Expand All @@ -111,16 +115,6 @@ sub nextOne {
# %cookie_jar will contain the cookies to use after redirects. Once the request is done, cookies are discarded.
my %cookie_jar ;


if ($ARGV[0])
{
$debugging_mode = ($ARGV[0] eq '-d' or $ARGV[0] eq '--debug') ? 1 : 0;
}
else
{
$debugging_mode = 0;
}

my $server_port = $debugging_mode || $mailnesia->{devel} ? $config->{smtp_port_devel} : $config->{smtp_port};
my $server_ip = $debugging_mode || $mailnesia->{devel} ? $config->{smtp_host_devel} : $config->{smtp_host};
my $dbh = $mailnesia->{dbh};
Expand Down
2 changes: 2 additions & 0 deletions script/clicker.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# ZeroMQ version used is 4.2.1

use FindBin;
use lib "$FindBin::Bin/../lib/";
use ZMQ::FFI qw(ZMQ_PUSH ZMQ_PULL);
use AnyEvent;
use EV;
Expand Down
2 changes: 1 addition & 1 deletion script/website.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# check SQL connection on each pageload, try to reconnect if fails
$mailnesia->connect_sql();

my $ip = $self->req->headers->header('X-Forwarded-For');
my $ip = $self->req->headers->header('X-Forwarded-For') || $self->tx->remote_address;

if ($ip) {
# redirect to captcha if too many mailbox requests
Expand Down Expand Up @@ -193,13 +193,13 @@

my $mailbox = $mailnesia->check_mailbox_characters( $original_url_decoded_mailbox );

my $emaillist_page = $self->param('p') =~ m/(\d+)/ ? $1 : 0;

Check failure on line 196 in script/website.pl

View workflow job for this annotation

GitHub Actions / test

Use of uninitialized value in pattern match (m//)

Check failure on line 196 in script/website.pl

View workflow job for this annotation

GitHub Actions / test

Use of uninitialized value in pattern match (m//)

Check failure on line 196 in script/website.pl

View workflow job for this annotation

GitHub Actions / test

Use of uninitialized value in pattern match (m//)

# this is used for ajax queries: when scrolling down the mailbox view, to automatically load the next page, and to check for new mail
my $noheadernofooter = $self->param("noheadernofooter");

# this is for polling for new mail
my $newerthan = $1 if $self->param('newerthan') =~ m/(\d+)/;

Check failure on line 202 in script/website.pl

View workflow job for this annotation

GitHub Actions / test

Use of uninitialized value in pattern match (m//)

Check failure on line 202 in script/website.pl

View workflow job for this annotation

GitHub Actions / test

Use of uninitialized value in pattern match (m//)


# forbidden if alias
Expand Down
Loading
Loading