Skip to content

Commit 0f33a42

Browse files
committed
Merge branch 'main' into patch-9
2 parents 3557080 + d935553 commit 0f33a42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3462
-753
lines changed

.github/workflows/functional.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: docker-compose-phpunit-functional
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
docker-compose-phpunit-functional:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
submodules: true
15+
- name: setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: "8.3"
19+
tools: composer
20+
- name: install composer dependencies
21+
run: composer update
22+
- name: Run docker compose
23+
uses: hoverkraft-tech/[email protected]
24+
with:
25+
compose-file: "./tools/docker-dev/docker-compose.yml"
26+
- name: Execute tests in the running services
27+
run: docker compose -f ./tools/docker-dev/docker-compose.yml exec -w '/var/www/unity-web-portal' web ./vendor/bin/phpunit --testsuite=functional

.github/workflows/lint.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/phpunit.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: phpunit
2+
3+
on: [push]
4+
5+
jobs:
6+
phpunit:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
with:
11+
submodules: true
12+
- name: setup PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: "8.3"
16+
# php extensions also listed in tools/docker-dev/web/Dockerfile and README.md
17+
extensions: curl,mysql,ldap,pdo,redis,intl
18+
tools: composer:v2
19+
- name: Install dependencies
20+
run: composer install --prefer-dist --no-progress
21+
- name: Run PHPUnit tests
22+
run: vendor/bin/phpunit --colors=always --testsuite unit

.github/workflows/pre-commit.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
submodules: true
15+
- uses: actions/setup-python@v3
16+
- name: setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: "8.3"
20+
tools: composer, phpcs, phpcbf
21+
- uses: pre-commit/[email protected]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ composer.lock
1616
deployment/*
1717
!deployment/**/README.md
1818
!deployment/deploy.sh
19+
20+
.phpunit.result.cache

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "hakasapl/phpopenldaper"]
2+
path = resources/lib/phpopenldaper
3+
url = https://github.com/hakasapl/phpopenldaper.git

.pre-commit-config.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# intentionally malformed files
2+
# pre-commit automatically excludes submodules
3+
exclude: |
4+
(?x)^(
5+
test/.*|
6+
)$
7+
8+
repos:
9+
# auto formatters (no work required) #############################################################
10+
# - repo: https://github.com/pre-commit/pre-commit-hooks
11+
# rev: v5.0.0
12+
# hooks:
13+
# - id: trailing-whitespace
14+
# - id: end-of-file-fixer
15+
- repo: local
16+
hooks:
17+
- id: phpcbf
18+
name: PHP Code Beautifier and Fixer
19+
entry: phpcbf
20+
language: system
21+
files: \.php$
22+
args: [--standard=PSR2, --colors]
23+
24+
# linters (work required) ########################################################################
25+
# - repo: https://github.com/pre-commit/pre-commit-hooks
26+
# rev: v5.0.0
27+
# hooks:
28+
# - id: check-yaml
29+
# - id: check-json
30+
# - id: check-xml
31+
# - id: check-added-large-files
32+
# - id: check-executables-have-shebangs
33+
# - repo: https://github.com/gitleaks/gitleaks
34+
# rev: v8.23.1
35+
# hooks:
36+
# - id: gitleaks
37+
- repo: local
38+
hooks:
39+
- id: phpcs
40+
name: PHP CodeSniffer
41+
entry: phpcs
42+
language: system
43+
files: \.php$
44+
args: [--standard=PSR2, --colors]
45+
- id: php-l
46+
name: php -l
47+
entry: php
48+
language: system
49+
files: \.php$
50+
args: [-l]
51+
- id: assert-no-die-exit
52+
name: Assert no die()/exit()
53+
entry: ./test/assert-no-die-exit.bash
54+
language: system
55+
files: \.php$
56+
exclude: resources/lib/UnitySite\.php$

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ The following users are available for testing:
5151

5252
### Changes to Dev Environment
5353

54-
Should the default schema of the web portal change, the `ldap/bootstrap.ldif` and `sql/bootstrap.sql` must be updated for the LDAP server and the MySQL server, respectively.
54+
Should the default schema of the web portal change, the `ldap/bootstrap.ldif` and `sql/bootstrap.sql` must be updated for the LDAP server and the MySQL server, respectively.

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ Unity Web Portal is a PHP application built in top of MariaDB and LDAP which act
2121
1. Some HTTP Authentication mechanism (such as Shibboleth SP)
2222
1. Composer (`apt install composer` on Ubuntu)
2323
1. PHP Extensions
24+
1. `php-cli`
25+
1. `php-curl`
26+
1. `php-intl`
2427
1. `php-ldap`
25-
2. `php-curl`
26-
3. `php-redis`
27-
4. `php-cli`
28-
5. `php-mysql`
29-
6. `php-pdo`
28+
1. `php-mbstring`
29+
1. `php-mysql`
30+
1. `php-pdo`
31+
1. `php-redis`
32+
1. `php-xml`
3033
2. Composer packages
3134
1. `cd` to this repository
32-
2. Install packages `composer update`
35+
1. Setup git submodules `git submodule update --init --checkout`
36+
1. Install packages `composer update`
3337
3. Setup config file `config/config.ini` according to your site deployment
3438
4. Setup branding file `config/branding/config.ini` according to your site deployment
3539
5. Point your web server's document root to `webroot` in this repo

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"require": {
33
"psr/log": "1.1.4",
4-
"phpseclib/phpseclib": "3.0.16",
5-
"phpmailer/phpmailer": "6.6.4",
6-
"hakasapl/phpopenldaper": "1.0.5"
4+
"phpseclib/phpseclib": "3.0.43",
5+
"phpmailer/phpmailer": "6.6.4"
6+
},
7+
"require-dev": {
8+
"phpunit/phpunit": "<12.1"
79
}
810
}

defaults/config.ini.default

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ name = "Unity Cluster" ; Name of the website
1111
url = "https://127.0.0.1:8000/" ; URL of the website
1212
description = "The Unity Web Portal is a lightweight HPC cluster front-end" ; Description of the website
1313
logo = "logo.png" ; path to logo file, in the webroot/assets/branding folder
14+
terms_of_service_url = "https://github.com" ; this can be external or a portal page created with "content management"
15+
account_policy_url = "https://github.com" ; this can be external or a portal page created with "content management"
1416

1517
[ldap]
1618
uri = "ldap://identity" ; URI of remote LDAP server
1719
user = "cn=admin,dc=unityhpc,dc=test" ; Admin bind DN LDAP user
1820
pass = "password" ; Admin bind password
1921
basedn = "dc=unityhpc,dc=test" ; Base search DN
20-
user_ou = "ou=users,dc=unityhpc,dc=test" ; User organizational unit
22+
user_ou = "ou=users,dc=unityhpc,dc=test" ; User organizational unit (may contain more than user group)
23+
user_group = "cn=unityusers,dc=unityhpc,dc=test" ; User group
2124
group_ou = "ou=groups,dc=unityhpc,dc=test" ; Group organizational unit
2225
pigroup_ou = "ou=pi_groups,dc=unityhpc,dc=test" ; PI Group organizational unit
2326
orggroup_ou = "ou=org_groups,dc=unityhpc,dc=test" ; ORG group organizational unit
24-
admin_group = "cn=sudo,dc=unityhpc,dc=test" ; admin dn (members of this group are admins on the web portal)
27+
admin_group = "cn=web_admins,dc=unityhpc,dc=test" ; admin dn (members of this group are admins on the web portal)
2528
def_user_shell = "/bin/bash" ; Default shell for new users
2629

2730
[sql]
@@ -74,6 +77,7 @@ title[] = "Test Medium Footer"
7477
[loginshell] ; Login shells that show up as options in the account settings page
7578
shell[] = "/bin/bash"
7679
shell[] = "/bin/zsh"
80+
shell[] = "/bin/tcsh"
7781

7882
[menuitems] ; menu items, add a label and link for each
7983
labels[] = "Global Menuitem 1"
@@ -100,4 +104,3 @@ url = "https://hooks.slack.com/services/T04BB3N3M26/B050A55CBNX/IGm1YA0VhjczAfs5
100104
[page] ; which sql objects to use for the content on these pages
101105
home = "home"
102106
support = "support"
103-
policy = "policy"

phpunit.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- restrictWarnings="true" -->
2+
<phpunit
3+
bootstrap="test/phpunit-bootstrap.php"
4+
failOnWarning="true"
5+
failOnDeprecation="true"
6+
failOnNotice="true"
7+
>
8+
<testsuites>
9+
<testsuite name="unit">
10+
<directory>test/unit</directory>
11+
</testsuite>
12+
<testsuite name="functional">
13+
<directory>test/functional</directory>
14+
</testsuite>
15+
</testsuites>
16+
</phpunit>

resources/autoload.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// Load Composer Libs
88
require_once __DIR__ . "/../vendor/autoload.php";
99

10+
// submodule
11+
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php";
12+
require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php";
13+
1014
// load libs
1115
require_once __DIR__ . "/lib/UnityLDAP.php";
1216
require_once __DIR__ . "/lib/UnityUser.php";
@@ -19,6 +23,7 @@
1923
require_once __DIR__ . "/lib/UnityConfig.php";
2024
require_once __DIR__ . "/lib/UnityWebhook.php";
2125
require_once __DIR__ . "/lib/UnityRedis.php";
26+
require_once __DIR__ . "/lib/UnityGithub.php";
2227

2328
// run init script
2429
require __DIR__ . "/init.php";

resources/init.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
* init.php - Initialization script that is run on every page of Unity
55
*/
66

7-
use UnityWebPortal\lib\{
8-
UnityConfig,
9-
UnityLDAP,
10-
UnityMailer,
11-
UnitySQL,
12-
UnitySSO,
13-
UnityUser,
14-
UnityRedis,
15-
UnityWebhook
16-
};
7+
use UnityWebPortal\lib\UnityConfig;
8+
use UnityWebPortal\lib\UnityLDAP;
9+
use UnityWebPortal\lib\UnityMailer;
10+
use UnityWebPortal\lib\UnitySQL;
11+
use UnityWebPortal\lib\UnitySSO;
12+
use UnityWebPortal\lib\UnityUser;
13+
use UnityWebPortal\lib\UnityRedis;
14+
use UnityWebPortal\lib\UnityWebhook;
15+
use UnityWebPortal\lib\UnityGithub;
1716

1817
//
1918
// Initialize Session
@@ -46,6 +45,7 @@
4645
$CONFIG["ldap"]["pigroup_ou"],
4746
$CONFIG["ldap"]["orggroup_ou"],
4847
$CONFIG["ldap"]["admin_group"],
48+
$CONFIG["ldap"]["user_group"],
4949
$CONFIG["ldap"]["def_user_shell"]
5050
);
5151

@@ -86,6 +86,8 @@
8686
$CONFIG["site"]["url"] . $CONFIG["site"]["prefix"]
8787
);
8888

89+
$GITHUB = new UnityGithub();
90+
8991
//
9092
// SSO Init
9193
//

resources/lib/UnityGithub.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace UnityWebPortal\lib;
4+
5+
class UnityGithub
6+
{
7+
public function getSshPublicKeys($username)
8+
{
9+
$url = "https://api.github.com/users/$username/keys";
10+
$headers = array(
11+
"User-Agent: Unity Cluster User Portal"
12+
);
13+
14+
$curl = curl_init();
15+
curl_setopt($curl, CURLOPT_URL, $url);
16+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
17+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
18+
$keys = json_decode(curl_exec($curl), false);
19+
curl_close($curl);
20+
21+
// normally returns array of objects each with a ->key attribute
22+
// if bad URL or no such user, returns status=404 object
23+
// if no keys, returns []
24+
if ((!is_array($keys)) || (count($keys) == 0)) {
25+
return [];
26+
}
27+
// phpcs:disable
28+
return array_map(function($x){return $x->key;}, $keys);
29+
// phpcs:enable
30+
}
31+
}

0 commit comments

Comments
 (0)