Setup CI testing

This commit is contained in:
Deon George 2020-08-23 12:30:18 +10:00
parent f3282bed38
commit 1e3e4b2196
11 changed files with 1981 additions and 83 deletions

54
.env.testing Normal file
View File

@ -0,0 +1,54 @@
APP_NAME=Laravel
APP_ENV=dev
APP_KEY=base64:KvIecx8zoy6RjcbJM8s98ZKs9IDGUHFVqBRn3Awfmso=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
LDAP_LOGGING=true
LDAP_AUTO_CONNECT=false
LDAP_HOSTS=ldap
LDAP_PORT=389
LDAP_BASE_DN="dc=Test"
LDAP_USERNAME=
LDAP_PASSWORD=
LDAP_ACCOUNT_PREFIX=
LDAP_ACCOUNT_SUFFIX=

64
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,64 @@
# This file is a template, and might need editing before it works on your project.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/php
image: registry.leenooks.net/leenooks/php:7.4-fpm-mp-test
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service
services:
- name: osixia/openldap:latest
alias: ldap
command: ["--loglevel","debug"]
variables:
LDAP_SEED_INTERNAL_LDIF_PATH: "${CI_PROJECT_DIR}/tests/server/openldap/ldif"
LDAP_BASE_DN: "dc=Test"
LDAP_DOMAIN: "Test"
LDAP_ADMIN_PASSWORD: test
# LDAP_SEED_INTERNAL_SCHEMA_PATH: "${CI_PROJECT_DIR}/tests/server/openldap/schema"
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- vendor/
# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
before_script:
# Install Composer and project dependencies.
- mkdir -p /root/.composer
- if [ -n "$GITHUB_TOKEN" ]; then cat $GITHUB_TOKEN |base64 -d > /root/.composer/auth.json ; fi
- composer install
# Copy over testing configuration.
# Don't forget to set the database config in .env.testing correctly
# DB_HOST=mysql
# DB_DATABASE=project_name
# DB_USERNAME=root
# DB_PASSWORD=secret
# Generate an application key. Re-cache.
- php artisan key:generate --env=testing
- php artisan config:cache --env=testing
test:
variables:
LDAP_HOST: ldap
LDAP_PORT: 389
tags:
- php
only:
- BRANCH-2.0
script:
# run laravel tests
- php vendor/bin/phpunit --coverage-text --colors=never
# run frontend tests
# if you have any task for testing frontend
# set it in your package.json script
# comment this out if you don't have a frontend test
# npm test

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Leenooks\LDAP; namespace App\Classes\LDAP;
use Adldap\Adldap; use Adldap\Adldap;
use Adldap\Models\Entry; use Adldap\Models\Entry;
@ -40,6 +40,8 @@ class Server
protected function getDNAttrValues(string $dn,array $attrs=['*','+'],int $deref=LDAP_DEREF_NEVER): ?Entry protected function getDNAttrValues(string $dn,array $attrs=['*','+'],int $deref=LDAP_DEREF_NEVER): ?Entry
{ {
try { try {
dump(config('ldap.connections.default.settings'));
return ($x=(new Adldap) return ($x=(new Adldap)
->addProvider(config('ldap.connections.default.settings')) ->addProvider(config('ldap.connections.default.settings'))
->search() ->search()
@ -48,7 +50,7 @@ class Server
// @todo Tidy up this exception // @todo Tidy up this exception
} catch (\Exception $e) { } catch (\Exception $e) {
dd(['e'=>$e,'s'=>$s]); dd(['e'=>$e]);
} }
} }
} }

View File

@ -4,12 +4,12 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Leenooks\LDAP; use App\Classes\LDAP\Server;
class HomeController extends Controller class HomeController extends Controller
{ {
public function home() { public function home() {
$o = new LDAP\Server; $o = new Server;
return view('home') return view('home')
->with('server',config('ldap.connections.default.name')) // @todo This connection name should be a config item ->with('server',config('ldap.connections.default.name')) // @todo This connection name should be a config item

View File

@ -14,8 +14,7 @@
"fruitcake/laravel-cors": "^2.0", "fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^6.3", "guzzlehttp/guzzle": "^6.3",
"laravel/framework": "^7.22.2", "laravel/framework": "^7.22.2",
"leenooks/laravel": "^7.0", "leenooks/laravel": "^7.0"
"leenooks/ldap": "dev-SANDPIT"
}, },
"require-dev": { "require-dev": {
"facade/ignition": "^2.0", "facade/ignition": "^2.0",
@ -53,10 +52,6 @@
{ {
"type": "vcs", "type": "vcs",
"url": "https://dev.leenooks.net/leenooks/laravel" "url": "https://dev.leenooks.net/leenooks/laravel"
},
{
"type": "path",
"url": "ldap"
} }
], ],
"minimum-stability": "dev", "minimum-stability": "dev",

44
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "7da3e0ebffd2d4cf4bc001dba98c3fba", "content-hash": "959ed9e0a5a540cea83879b015a2a00c",
"packages": [ "packages": [
{ {
"name": "adldap2/adldap2", "name": "adldap2/adldap2",
@ -1454,43 +1454,6 @@
], ],
"time": "2020-08-04T06:14:35+00:00" "time": "2020-08-04T06:14:35+00:00"
}, },
{
"name": "leenooks/ldap",
"version": "dev-SANDPIT",
"dist": {
"type": "path",
"url": "ldap",
"reference": "2d5349d22b5d248bdf7377b67ac65ae53bd9b882"
},
"require": {
"adldap2/adldap2-laravel": "^6.0",
"ext-ldap": "*",
"php": ">=7.2"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Leenooks\\LDAP\\LaravelServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Leenooks\\LDAP\\": "src/"
}
},
"authors": [
{
"name": "Deon George",
"email": "deon@leenooks.net"
}
],
"description": "LDAP Library",
"transport-options": {
"relative": true
}
},
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "2.1.1", "version": "2.1.1",
@ -6208,6 +6171,7 @@
"keywords": [ "keywords": [
"tokenizer" "tokenizer"
], ],
"abandoned": true,
"time": "2019-09-17T06:23:10+00:00" "time": "2019-09-17T06:23:10+00:00"
}, },
{ {
@ -7163,9 +7127,7 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": [],
"leenooks/ldap": 20
},
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {

View File

@ -1,28 +0,0 @@
{
"name": "leenooks/ldap",
"description": "LDAP Library",
"type": "library",
"authors": [
{
"name": "Deon George",
"email": "deon@leenooks.net"
}
],
"require": {
"php": ">=7.2",
"ext-ldap": "*",
"adldap2/adldap2-laravel": "^6.0"
},
"autoload": {
"psr-4": {
"Leenooks\\LDAP\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Leenooks\\LDAP\\LaravelServiceProvider"
]
}
}
}

View File

@ -14,18 +14,23 @@
<div class="card card-solid"> <div class="card card-solid">
<div class="card-body"> <div class="card-body">
<div class="row"> <div class="row">
<div class="col-12 col-sm-6"> <div class="col-12 col-sm-4">
<h3 class="d-inline-block d-sm-none">phpLDAPadmin</h3> <h3 class="d-inline-block d-sm-none">phpLDAPadmin</h3>
<div class="col-12"> <div class="col-12">
<img src="img/logo.png" class="product-image" alt="PLA Logo"> <img src="img/logo.png" class="product-image" alt="PLA Logo">
</div> </div>
</div> </div>
<div class="col-12 col-sm-6"> <div class="col-12 col-sm-8">
<h3 class="mb-1">Welcome to phpLDAPadmin</h3> <h3 class="mb-1">Welcome to phpLDAPadmin</h3>
<h4 class="mb-3"><small>{{ config('app.version') }}</small></h4> <h4 class="mb-3"><small>{{ config('app.version') }}</small></h4>
<p>phpLDAPadmin (or PLA for short) is an LDAP data management tool for administrators.</p> <p>phpLDAPadmin (or PLA for short) is an LDAP data management tool for administrators.</p>
<p>PLA aims to adhere to the LDAP standards (RFC4511) so that it can interact with any LDAP server that implements those standards.</p> <p>PLA aims to adhere to the LDAP standards (<a href="https://tools.ietf.org/html/rfc4511">RFC4511</a>) so that it can interact with any LDAP server that implements those standards.</p>
</div>
</div>
<div class="row">
<div class="col-12">
<hr> <hr>
<p>Version 2 is a complete re-write of PLA, leveraging the advancements and modernisation of web tools and methods, libraries since version 1 was released.</p> <p>Version 2 is a complete re-write of PLA, leveraging the advancements and modernisation of web tools and methods, libraries since version 1 was released.</p>
<p>You can support this application by letting us know which LDAP server you use (including version and platform).</p> <p>You can support this application by letting us know which LDAP server you use (including version and platform).</p>

View File

@ -0,0 +1,21 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/home');
$response->assertStatus(200);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Tests\Unit;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Leenooks\LDAP\Server;
class GetBaseDNTest extends TestCase
{
/**
* Test that we can get the Base DN of an LDAP server
*
* @return void
*/
public function testBaseDNExists()
{
$o = new Server;
$x = $o->getBaseDN();
$this->assertIsObject($x);
$this->assertCount(1,$x->toArray());
$this->assertContains('dc=Test',$x->toArray());
}
}

File diff suppressed because it is too large Load Diff