From fb63c5c562de48ccf0996bc8eb7392a9fedb43af Mon Sep 17 00:00:00 2001 From: "John (Github)" <48443038+wangxiaoerYah@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:54:49 +0800 Subject: [PATCH] workflows: add test --- .github/tests/hm3.ini | 552 +++++++++++++++++++++++++++++++++++++ .github/tests/my.cnf | 4 + .github/tests/setup.sh | 87 ++++++ .github/tests/test.sh | 27 ++ .github/workflows/test.yml | 81 ++++++ 5 files changed, 751 insertions(+) create mode 100644 .github/tests/hm3.ini create mode 100644 .github/tests/my.cnf create mode 100644 .github/tests/setup.sh create mode 100644 .github/tests/test.sh create mode 100644 .github/workflows/test.yml diff --git a/.github/tests/hm3.ini b/.github/tests/hm3.ini new file mode 100644 index 0000000000..fc04fcf4a4 --- /dev/null +++ b/.github/tests/hm3.ini @@ -0,0 +1,552 @@ + +; ----------------------------------------------------------------------------- +; General settings +; ----------------------------------------------------------------------------- + +; Session Type +; ------------ +; Sessions are how the server maintains your logged in state. Cypht supports +; standard PHP sessions, as well as it's own completely independent session +; system that uses memcached or a database for storage. In order to use +; database sessions the database must be correctly configured in the "DB +; Support" section and the hm_user_session table must be created. In order to +; use Memcached sessions, the memcached server must be correctly configured +; in the "Memcached Support" section. +; +; Valid values for this setting: +; +; PHP Standard PHP session handlers +; DB Custom database based sessions +; MEM Custom Memcached based sessions +; +session_type=PHP + + +; Authentication Type +; ------------------- +; This setting defines how Cypht will authenticate your username and password +; when you login. If you want to use a database it must be correctly configured +; in the "DB Support" section and the hm_user table must be created. There are +; 3 PHP cli scripts to help manage database users in the scripts/ directory ( +; create_account.php, delete_account.php, and update_password.php). If you want +; to authenticate against an IMAP server, you must setup the imap_auth_* settings +; below. If you want to authenticate against an LDAP server, +; you must setup the ldap_auth_* settings. Finally, if you want to let users +; pick from a list of popular mail services or try to auto-discover a mail +; system, set this to dynamic and make sure the dynamic_login module set is +; enabled in the "Module Sets" section of this file. +; +; Valid values for this setting: +; +; DB Authenticate against the database +; LDAP Authenticate against an LDAP server +; IMAP Authenticate using an IMAP server +; dynamic Let the user choose from a list, or try to auto discover the mail +; services based on the E-mail domain +; +auth_type=IMAP + + +; LDAP Authentication +; ------------------- +; If auth_type is set to LDAP, configure the LDAP server to authenticate against +; with the following settings, otherwise these are ignored. +; + +; The hostname or IP address of the LDAP server to authenticate to +ldap_auth_server=localhost + +; The port the LDAP server is listening on. +ldap_auth_port=389 + +; Enable TLS/SSL connections. Leave blank or set to false to disable. Set to +; true to enable TLS connections. +ldap_auth_tls= + +; The "base dn" of the LDAP server +ldap_base_dn="example,dc=com" + + +; IMAP Authentication +; ------------------- +; If auth_type is set to IMAP, configure the IMAP server to authenticate against +; with the following settings, otherwise these are ignored. +; +; This is just a label used in the UI. It can be set to anything +imap_auth_name=localhost + +; The hostname or IP address of the IMAP server to authenticate to +imap_auth_server=localhost + +; The port the IMAP server is listening on. +imap_auth_port=143 + +; Enable TLS/SSL connections. Leave blank or set to false to disable. Set to +; true to enable TLS connections. If you want to use IMAP STARTTLS, do NOT +; enable this. This is only for TLS enabled sockets (typically on port 993). +imap_auth_tls=false + + +; Default SMTP Server +; ------------------- +; You can set a default SMTP server for all Cypht users. Authentication will be +; done with the users login credentials, so this only makes sense if you are +; using IMAP for authentication. Leave these values blank to disable a +; default SMTP server, otherwise fill in the required values below +; +; This is just a label used in the UI. It can be set to anything +default_smtp_name=localhost + +; The hostname or IP address of the SMTP server +default_smtp_server=localhost + +; The port the SMTP server is listening on. +default_smtp_port=25 + +; Enable TLS/SSL connections. Leave blank or set to false to disable. Set to +; true to enable TLS connections. +default_smtp_tls= + +; If your SMTP service does not require authentication, you can disable it +; by setting the following to true. +default_smtp_no_auth=true + + +; Settings Storage +; ---------------- +; Cypht supports 2 methods for saving user settings between logins. File based +; settings or in a database table. To store settings in a database, it must be +; configured in the "DB Support" section and the hm_user_settings table must be +; created. To store settings on the filesystem, the user_settings_dir must be +; created and the webserver software must be able to write to it. +; +; Valid values for this setting: +; +; file Store user settings in the filesystem +; DB Store user settings in a database +; +user_config_type=file + + +; Settings Location +; ----------------- +; If user_config_type is set to file, this must be set to an existing directory +; that the webserver software can read and write to. If settings storage is set +; to DB, this is ignored. It should not be inside the webserver document root. +user_settings_dir=/tmp + + +; Attachment Location +; ------------------- +; Cypht needs a temporary place to store attachments that are to be sent with +; an outgoing message. This folder must exist and be writable by the webserver +; software. It should not be inside the webserver document root. +attachment_dir=/tmp + + +; Application Data Location +; ------------------------- +; Some Cypht module sets have their own ini files that need to be readable by +; the webserver software, but not writable, and definitely not inside the +; webserver document root. +app_data_dir=/tmp + + +; Disable HTTPS Redirect +; --------------------- +; By default Cypht will not allow unencrypted HTTP requests, only HTTPS. If you +; manage this differently, or know what you are doing, set the following to true +; to disable the HTTPS redirect. +; +; Valid values for this setting +; +; true Disable HTTPS redirect +; false (or blank) Redirect HTTP requests to HTTPS +; +disable_tls=true + + +; Disable origin check +; -------------------- +; To help protect against CSRF attacks, Cypht checks origin headers to confirm +; that the source and target origin domains match. If you are using proxies this +; could create a problem making it impossible to login. Change this to true to +; disable the origin check. +disable_origin_check=false + + +; Admin Users +; ---------- +; You can define a comma delimited list of admin users that Cypht will grant +; special rights to. Currently this only enables the "create account" link in +; the account module set that provides a form to create a new account. This is +; only used if the auth_type is set to DB. Leave this blank if you don't want +; to define any admin users, or are using IMAP authentication. +admin_users= + + +; Cookie Domain +; ------------- +; By default Cypht uses the server name used in the request to determine +; the domain name to set the cookie for. Configurations that use a reverse +; proxy might need to define the domain name used for cookies. Leave this +; blank to let Cypht auotmatically determine the domain. You can also use +; the special value of "none" to force Cypht to NOT set the cookie domain +; property at all. This is not recommended unless you know what you are +; doing! +cookie_domain= + + +; Outbound E-mail Domain +; ---------------------- +; Default domain used for outbound E-mail addresses when using IMAP auth and +; users don't login with a full E-mail address. Users can customize this with +; the profiles module which will override this default +default_email_domain= + + +; Redirect After Login +; -------------------- +; You can login directly to any page in Cypht by going to the correct url before +; logging in, but that is not very user friendly. To redirect users to a url +; after login add the url arguments below (everything in the url after, but +; including, the question mark). You must use double quotes around the value +; otherwise it will cause an ini parsing error. To redirect users after login +; to the combined unread view you would use: +; +; redirect_after_login="?page=message_list&list_path=unread" +redirect_after_login= + + +; Application Name +; ---------------- +; This label is used in the UI to reference the program - you can change it to +; "Your awesome webmail" to replace the Cypht name used in various places. +app_name=Cypht + + +; Default Language +; ---------------- +; Users can select from available interface languages on the site settings page. +; This sets the default for a user who has not done so. Valid values are 2 character +; langauge codes that have matching language definitions in the language/ folder. +default_language=en + + +; JavaScript Compression +; ---------------------- +; When the configuration script is run, all JavaScript files are concatenated +; and optionally compressed. To compress the content, define a command and it's +; options below. Cypht does not come with compresson software, so you must +; install and configure that separately. Leave blank or set to false to disable +; external compression. +; +; Examples: +; js_compress='java -jar /usr/local/lib/yuicompressor-2.4.8.jar --type js' +; js_compress='uglifyjs -nc --unsafe -c -v' +; +js_compress=false + + +; CSS Compression +; --------------- +; When the configuration script is run, all CSS files are concatenated and +; optionally compressed. To compress the content, define a command and it's +; options below. Cypht does not come with compresson software, so you must +; install and configure that separately. Leave blank or set to false to disable +; external compression. +; +; Example: +; css_compress='java -jar /usr/local/lib/yuicompressor-2.4.8.jar --type css' +; +css_compress=false + + +; Memcached Support +; ----------------- +; Cypht can use memcached to cache data. If this enabled, modules that support +; memcache will attempt to use it to improve performance. Currently, only the +; feeds module uses this option. +enable_memcached=true +memcached_server=127.0.0.1 +memcached_port=11211 + + +; Browser Encryption Options +; -------------------------- +; WARNING: These options are still experimental and cause problems. Specifically +; character set issues could occur, and the history module set breaks when the +; local storage option is enabled. +; +; Cypht can use the Forge JavaScript encryption library to encrypt AJAX +; responses and data stored in browser local storage Enabling either one of +; these options causes the forge javascript library to be included. This adds +; about 70KB to the page size (when gzipped). + +; Use AES encryption for ajax responses. Set to true to enable, leave blank or +; set to false to disable. +encrypt_ajax_requests= + +; Use AES encryption for data stored in the browser local storage. Set to true +; to enable, or leave blank or set to false to disable. +encrypt_local_storage= + + +; ----------------------------------------------------------------------------- +; DB Support +; ----------------------------------------------------------------------------- + +; Database Support +; ---------------- +; Cypht can use a database for 3 different purposes: authentication, sessions, +; and user settings. Each requires the following settings to be configured and +; the correct table to be created. CREATE TABLE SQL statements for Mysql and +; Postgresql are below. +; +; Connection type. Can be "host" to connect to a hostname, or "socket" to +; connect to a unix socket. +db_connection_type=host + +; Database host name or ip address. If db_connection_type is set to "socket", +; this value is ignored +db_host=127.0.0.1 + +; If db_connection_type is set to "socket", this should be the filesystem +; location of the unix socket file. If db_connection_type is set to "host" +; this value is ignored. +db_socket= + +; Name of the database with the required tables +db_name=cypht_test + +; User to connect to the database with +db_user=cypht_test + +; Password to connect to the database with +db_pass=cypht_test + +; Database type. can be any supported PDO driver ; (http://php.net/manual/en/pdo.drivers.php) +db_driver=mysql + + +; DB Sessions +; ----------- +; If your session_type is set to DB the following table must exist in the DB +; defined above, and the db user must have read-write access to it: +; +; Postgresql: +; CREATE TABLE hm_user_session (hm_id varchar(250) primary key not null, data text, date timestamp); +; +; Mysql or sqlite: +; CREATE TABLE hm_user_session (hm_id varchar(250), data longblob, date timestamp, primary key (hm_id)); + + +; DB Authentication +; ----------------- +; If your auth_type is set to DB, the following table must exist in the DB +; defined above, and the db user must have read-write access to it: +; +; Postgresql: +; CREATE TABLE hm_user (username varchar(255) primary key not null, hash varchar(255)); +; +; Mysql or sqlite: +; CREATE TABLE hm_user (username varchar(250), hash varchar(250), primary key (username)); + + +; DB Settings +; ----------- +; If your user_config_type is set to DB, the following table must exist in the +; DB defined above, and the db user must have read-write access to it: +; +; Postgresql: +; CREATE TABLE hm_user_settings (username varchar(250) primary key not null, settings text); +; +; Mysql or sqlite: +; CREATE TABLE hm_user_settings(username varchar(250), settings longblob, primary key (username)); + + +; ----------------------------------------------------------------------------- +; Modules +; ----------------------------------------------------------------------------- + +; Module Sets +; ----------- +; Cypht uses module sets to separate functionality in the program. Module sets +; can be enabled and disabled independently by commenting out or uncommenting +; the assignments below. Add a new assignment to enable your own module sets. + + +; Core +; ---- +; Handles page layout, login/logout, and the default settings pages. This set +; is required. +modules[]=core + +; Contacts +; ------- +; Contact support. This module requires that at least one "backend" contacts +; module be enabled (ldap_contacts, gmail_contacts, or local_contacts). You +; can enable all the backends you want to support. +modules[]=contacts + +; Local contact support. Simple, locally stored contacts backend +modules[]=local_contacts + +; LDAP contact support. Use an LDAP server to store contacts. This module +; uses it's own ini file in modules/ldap_contacts/. This file must be edited +; and moved to your app_data_dir to configure LDAP access. +; modules[]=ldap_contacts + +; Gmail contact support. Read-only support for Gmail contacts. Only available +; if you have a Gmail account enabled that uses Oauth2 authentication +; modules[]=gmail_contacts + +; Feeds +; ----- +; RSS/ATOM feed support +modules[]=feeds + +; IMAP +; ---- +; IMAP E-mail account support. If you want to use Oauth2 over IMAP (currently +; only supported by Gmail and Outlook.com), you will need to edit the oauth2.ini +; file in modules/imap/, and move it to your app_data_dir location. +modules[]=imap + +; 2 factor authentication +; ----------------------- +; This module enables 2 factor authentication using TOTP (compatible with +; Google Authenticator). You must edit the ini file in modules/2fa/ to +; configure a shared secret, then move that file to your app_data_dir. +; modules[]=2fa + +; SMTP +; ---- +; Send outbound E-mail using SMTP servers +modules[]=smtp + +; Account +; ------ +; UI features for admins to create accounts, and for users to update passwords +; (when using the built-in DB authentication) +; modules[]=account + +; Idle timer +; --------- +; Controls idle time and automatic logout +modules[]=idle_timer + +; Calendar +; ------- +; Basic calendar +modules[]=calendar + +; Themes +; ------ +; Change the UI using CSS +modules[]=themes + +; NUX +; --- +; Friendly new user experience. Quickly add common E-mail services, and view +; development updates +modules[]=nux + +; Developer +; --------- +; For development, provides resources and installation details. Only available +; in "debug mode" +modules[]=developer + +; Github +; ------ +; Github repository tracking. This module has it's own ini file located in +; modules/github/. You must edit this file, and move it to your app_data_dir +; to establish communication with github. +; modules[]=github + +; Recaptcha +; --------- +; Use the Recaptcha server on login. This module has it's own ini file in +; modules/recaptcha/. You must edit this file, and move it to the location +; defined in app_data_dir to gain access to the WordPress notification API. +; modules[]=recaptcha + +; WordPress +; --------- +; WordPress.com notifications. This module has it's own ini file in +; modules/wordpress/. You must edit this file, and move it to the location +; defined in app_data_dir to gain access to the WordPress notification API. +; modules[]=wordpress + +; History +; ------- +; Simple list of messages read since login +modules[]=history + +; Saved searches +; -------------- +; Save and re-run searches easily +modules[]=saved_searches + +; NASA +; ---- +; Access the NASA APOD API content +; modules[]=nasa + +; Profiles +; -------- +; Profiles to set reply-to, name, and signature to associated E-mail accounts +modules[]=profiles + +; Inline message +; -------------- +; View messages inline in a reading pane instead of on a new page +modules[]=inline_message + +; IMAP folders +; ----------- +; Support for adding/renaming/deleting folders in IMAP accounts +modules[]=imap_folders + +; Keyboard Shortcuts +; ------------------ +; Enables configurable keyboard shortcuts for navigations and actions +modules[]=keyboard_shortcuts + +; Site +; ---- +; Site specific overrides. Used to control other module sets without hacking +; the code. +; modules[]=site + +; Dynamic login +; ------------- +; Allows user to authenticate against a list of popular mail services, or to +; auto-discover the services for the specified E-mail address. The auth_type +; setting must be set to "dynamic", otherwise this module set does not do +; anything +; modules[]=dynamic_login + +; API login +; -------- +; Allows an API based login that returns a JSON response containing the session +; and hm_id values needed to create a login session. You will need to set the +; api_login_key value to something unique and include that in the POST request. +; modules[]=api_login +; api_login_key= + +; Recover settings +; ---------------- +; When using IMAP authentication, if a user's password is changed, we +; can't decrypt the existing user settings. This module detects that situation +; and provides a page where a user can enter their old and new passwords to +; recover their previous settings. +; modules[]=recover_settings + +; Hello World +; ----------- +; Example module set with lots of comments +; modules[]=hello_world +; +default_setting_theme='default' diff --git a/.github/tests/my.cnf b/.github/tests/my.cnf new file mode 100644 index 0000000000..75fe4ff78e --- /dev/null +++ b/.github/tests/my.cnf @@ -0,0 +1,4 @@ +[client] +user = "cypht_test" +password = "cypht_test" +host = "127.0.0.1" \ No newline at end of file diff --git a/.github/tests/setup.sh b/.github/tests/setup.sh new file mode 100644 index 0000000000..1e4a84dff4 --- /dev/null +++ b/.github/tests/setup.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# Configure Cypht +setup_cypht() { + cp .github/tests/hm3.ini . + if [ "$DB" = "postgres" ]; then + sed -i 's/db_driver=mysql/db_driver=pgsql/' hm3.ini + sed -i 's/mysql/pgsql/' tests/phpunit/mocks.php + fi + if [ "$DB" = "sqlite" ]; then + sed -i 's/db_driver=mysql/db_driver=sqlite/' hm3.ini + sed -i 's/mysql/sqlite/' tests/phpunit/mocks.php + sed -i "s/'host'/'socket'/" tests/phpunit/mocks.php + fi +} + +# Create and populate database for phpunit tests +setup_db() { + echo "SETTING UP DB $DB" + if [ "$DB" = "postgres" ]; then + PGPASSWORD=cypht_test psql -h 127.0.0.1 -U cypht_test -d cypht_test -c 'CREATE TABLE hm_user (username varchar(255) primary key not null, hash varchar(255));' + PGPASSWORD=cypht_test psql -h 127.0.0.1 -U cypht_test -d cypht_test -c 'CREATE TABLE hm_user_session (hm_id varchar(250) primary key not null, data text, date timestamp);' + PGPASSWORD=cypht_test psql -h 127.0.0.1 -U cypht_test -d cypht_test -c 'CREATE TABLE hm_user_settings (username varchar(250) primary key not null, settings text);' + PGPASSWORD=cypht_test psql -h 127.0.0.1 -U cypht_test -d cypht_test -c "insert into hm_user values('unittestuser', 'sha512:86000:xfEgf7NIUQ2XkeU5tnIcA+HsN8pUllMVdzpJxCSwmbsZAE8Hze3Zs+MeIqepwocYteJ92vhq7pjOfrVThg/p1voELkDdPenU8i2PgG9UTI0IJTGhMN7rsUILgT6XlMAKLp/u2OD13sukUFcQNTdZNFqMsuTVTYw/Me2tAnFwgO4=:rfyUhYsWBCknx6EmbeswN0fy0hAC0N3puXzwWyDRquA=');" + PGPASSWORD=cypht_test psql -h 127.0.0.1 -U cypht_test -d cypht_test -c "insert into hm_user values('testuser', '\$argon2id\$v=19\$m=65536,t=2,p=1\$dw4pTU24zRKHCEkLcloU/A\$9NJm6ALQhVpB2HTHmVHjOai912VhURUDAPsut5lrEa0');" + PGPASSWORD=cypht_test psql -h 127.0.0.1 -U cypht_test -d cypht_test -c "insert into hm_user_settings values('testuser', 'sFpVPU/hPvmfeiEKUBs4w1EizmbW/Ze2BALZf6kdJrIU3KVZrsqIhKaWTNNFRm3p51ssRAH2mpbxBMhsdpOAqIZMXFHjLttRu9t5WZWOkN7qwEh2LRq6imbkMkfqXg//K294QDLyWjE0Lsc/HSGqnguBF0YUVLVmWmdeqq7/OrXUo4HNbU88i4s2gkukKobJA2hjcOEq/rLOXr3t4LnLlcISnUbt4ptalSbeRrOnx4ehZV8hweQf1E+ID7s/a+8HHx1Qo713JDzReoLEKUsxRQ==');" + fi + if [ "$DB" = "mysql" ]; then + mysql --defaults-extra-file=.github/tests/my.cnf -e 'create table hm_user (username varchar(255), hash varchar(255), primary key (username));' cypht_test + mysql --defaults-extra-file=.github/tests/my.cnf -e 'create table hm_user_session (hm_id varchar(255), data longblob, date timestamp, primary key (hm_id));' cypht_test + mysql --defaults-extra-file=.github/tests/my.cnf -e 'create table hm_user_settings(username varchar(255), settings longblob, primary key (username));' cypht_test + mysql --defaults-extra-file=.github/tests/my.cnf -e "insert into hm_user values('unittestuser', 'sha512:86000:xfEgf7NIUQ2XkeU5tnIcA+HsN8pUllMVdzpJxCSwmbsZAE8Hze3Zs+MeIqepwocYteJ92vhq7pjOfrVThg/p1voELkDdPenU8i2PgG9UTI0IJTGhMN7rsUILgT6XlMAKLp/u2OD13sukUFcQNTdZNFqMsuTVTYw/Me2tAnFwgO4=:rfyUhYsWBCknx6EmbeswN0fy0hAC0N3puXzwWyDRquA=');" cypht_test + mysql --defaults-extra-file=.github/tests/my.cnf -e "insert into hm_user values('testuser', '\$argon2id\$v=19\$m=65536,t=2,p=1\$dw4pTU24zRKHCEkLcloU/A\$9NJm6ALQhVpB2HTHmVHjOai912VhURUDAPsut5lrEa0');" cypht_test + mysql --defaults-extra-file=.github/tests/my.cnf -e "insert into hm_user_settings values('testuser', 'sFpVPU/hPvmfeiEKUBs4w1EizmbW/Ze2BALZf6kdJrIU3KVZrsqIhKaWTNNFRm3p51ssRAH2mpbxBMhsdpOAqIZMXFHjLttRu9t5WZWOkN7qwEh2LRq6imbkMkfqXg//K294QDLyWjE0Lsc/HSGqnguBF0YUVLVmWmdeqq7/OrXUo4HNbU88i4s2gkukKobJA2hjcOEq/rLOXr3t4LnLlcISnUbt4ptalSbeRrOnx4ehZV8hweQf1E+ID7s/a+8HHx1Qo713JDzReoLEKUsxRQ==');" cypht_test + fi + if [ "$DB" = "sqlite" ]; then + touch /tmp/test.db + sqlite3 /tmp/test.db 'create table hm_user (username varchar(255), hash varchar(255), primary key (username));' + sqlite3 /tmp/test.db 'create table hm_user_session (hm_id varchar(255), data longblob, date timestamp, primary key (hm_id));' + sqlite3 /tmp/test.db 'create table hm_user_settings(username varchar(255), settings longblob, primary key (username));' + sqlite3 /tmp/test.db "insert into hm_user values('unittestuser', 'sha512:86000:xfEgf7NIUQ2XkeU5tnIcA+HsN8pUllMVdzpJxCSwmbsZAE8Hze3Zs+MeIqepwocYteJ92vhq7pjOfrVThg/p1voELkDdPenU8i2PgG9UTI0IJTGhMN7rsUILgT6XlMAKLp/u2OD13sukUFcQNTdZNFqMsuTVTYw/Me2tAnFwgO4=:rfyUhYsWBCknx6EmbeswN0fy0hAC0N3puXzwWyDRquA=');" + sqlite3 /tmp/test.db "insert into hm_user values('testuser', '\$argon2id\$v=19\$m=65536,t=2,p=1\$dw4pTU24zRKHCEkLcloU/A\$9NJm6ALQhVpB2HTHmVHjOai912VhURUDAPsut5lrEa0');" + sqlite3 /tmp/test.db "insert into hm_user_settings values('testuser', 'sFpVPU/hPvmfeiEKUBs4w1EizmbW/Ze2BALZf6kdJrIU3KVZrsqIhKaWTNNFRm3p51ssRAH2mpbxBMhsdpOAqIZMXFHjLttRu9t5WZWOkN7qwEh2LRq6imbkMkfqXg//K294QDLyWjE0Lsc/HSGqnguBF0YUVLVmWmdeqq7/OrXUo4HNbU88i4s2gkukKobJA2hjcOEq/rLOXr3t4LnLlcISnUbt4ptalSbeRrOnx4ehZV8hweQf1E+ID7s/a+8HHx1Qo713JDzReoLEKUsxRQ==');" + fi +} + +# Setup base data needed by the phpunit tests +bootstrap_unit_tests() { + setup_db + echo '+2IdQejfHu4FNYOA3tm0DJVQNg92gcpJf8ETeVj+HK0OU6J5iaV/J823rLm8+5Et7tQLoCCoZwElGTH7N2P2M4JMct1jRyWgjqJQn9FYlovFYj/8fLwkixGo+VMNIKsUwJ42GXTj61nn0Rf4+FO688SfAR5LhaLTXlR6XZ9mJD2/2RX1X+Z1JVl7SrqELgE8wnz5IYCrzqBbgK4MDn86rTtPM9jie3gFS9viMZ7OQRENbXLvwBaIXNLvQlZZn2JBdzXF1spoLnSlq8P0pYXlDig==' > tests/phpunit/data/testuser.txt +} + +# output some system info +sys_info() { + df -h + sudo netstat -lntp +} + +# setup just what is needed for the phpunit unit tests +setup_unit_tests() { + setup_cypht + bootstrap_unit_tests +} + +setup_ui_tests() { + echo "To do..." +} + +# Main +echo "database: ${DB}" +echo "php-version: ${PHP_V}" +echo "test-arg: ${TEST_ARG}" + +ARG="${TEST_ARG}" +case "$ARG" in + phpunit) + setup_unit_tests + ;; + ui) + setup_ui_tests + ;; + *) + setup_unit_tests + ;; +esac + +sys_info diff --git a/.github/tests/test.sh b/.github/tests/test.sh new file mode 100644 index 0000000000..a0f1447955 --- /dev/null +++ b/.github/tests/test.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +phpunit_tests() { + phpunit --configuration tests/phpunit/phpunit.xml --testdox +} + +selenium_tests() { + cd tests/selenium/ && sh ./runall.sh && cd ../../ +} + +# Main +echo "database: ${DB}" +echo "php-version: ${PHP_V}" +echo "test-arg: ${TEST_ARG}" + +ARG="${TEST_ARG}" +case "$ARG" in + phpunit) + phpunit_tests + ;; + ui) + selenium_tests + ;; + *) + phpunit_tests + ;; +esac diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..bd44cdd4ad --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,81 @@ +name: Test CI + +defaults: + run: + shell: bash + +on: + push: + branches: + - master + workflow_dispatch: # on button click +#permissions: write-all + +jobs: + Test: + runs-on: ubuntu-latest + + strategy: + matrix: + php-versions: ['7.4'] + database: ['mysql', 'postgres', 'sqlite'] + + env: + PHP_V: ${{ matrix.php-versions }} + DB: ${{ matrix.database }} + TEST_ARG: 'phpunit' + + services: + mysql: + image: mysql:latest + env: + MYSQL_ROOT_PASSWORD: cypht_test + MYSQL_DATABASE: cypht_test + MYSQL_USER: cypht_test + MYSQL_PASSWORD: cypht_test + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + postgresql: + image: postgres:latest + env: + POSTGRES_USER: cypht_test + POSTGRES_PASSWORD: cypht_test + POSTGRES_DB: cypht_test + ports: + - 5432:5432 + options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: "System Install Dependencies" + run: sudo apt-get install -y mysql-client postgresql-client sqlite3 libsodium-dev + + - name: "Checkout code" + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: "Set up PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: pdo, sodium, sqlite, pdo_mysql, pdo_pgsql, memcached, redis, gd, gnupg + tools: phpunit, composer + ini-values: cgi.fix_pathinfo=1 + env: + fail-fast: true + + - name: "Script: setup.sh" + run: bash .github/tests/setup.sh + + - name: "Composer Install Dependencies" + run: | + composer install + composer require --dev php-coveralls/php-coveralls + php scripts/config_gen.php + + - name: "Script: test.sh" + run: bash .github/tests/test.sh + +