Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #98 from govCMS/feature/nginx-testing
Browse files Browse the repository at this point in the history
[GOVCMSD7-276] Add BDD/Unit testing for nginx configuration.
  • Loading branch information
SRowlands authored Jan 7, 2020
2 parents 895c5f2 + ab253ed commit a7031b3
Show file tree
Hide file tree
Showing 24 changed files with 1,984 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ jobs:
else
echo "Redis success: Redis contains $redisKeys keys."
fi
- run:
name: Test nginx configuration
command: |
docker-compose exec nginx nginx -t
composer install -d .docker/images/nginx/tests
.docker/images/nginx/tests/vendor/bin/phpunit -c .docker/images/nginx/tests/phpunit.xml
workflows:
version: 2
main:
Expand Down
2 changes: 0 additions & 2 deletions .docker/Dockerfile.nginx-drupal
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ FROM amazeeio/nginx-drupal:${LAGOON_IMAGE_VERSION}

# nginx config.
COPY .docker/images/nginx/helpers/ /etc/nginx/helpers/
COPY .docker/images/nginx/x_frame_options.conf /etc/nginx/conf.d/drupal/location_drupal_append_x_frame_options.conf
COPY .docker/images/nginx/no_robots_govcms_host.conf /etc/nginx/conf.d/drupal/location_drupal_prepend_no_robots_govcms_host.conf
COPY .docker/images/nginx/no-robots.sh /lagoon/entrypoints/20-no-robots.sh
RUN fix-permissions /etc/nginx

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## ACSF Redirects.

# Theme directory.
rewrite ^\/sites\/g\/files\/net(\d+)\/themes\/site\/(.+)\/(.*)$ /sites/default/themes/custom/$2/$3?acsf_theme_redirect last;
rewrite ^\/sites\/g\/files\/net(\d+)\/themes\/site\/(.+)\/(.*)$ /sites/default/themes/custom/$2/$3?acsf_theme_redirect permanent;

# Files directory.
location ~* ^/sites/g/files/net(?:\d+)/f/(.+)$ {
Expand Down
14 changes: 14 additions & 0 deletions .docker/images/nginx/helpers/206-x_robots_tag_header.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
###
### Add the X-Robots-Tag to the server response
### @see https://developers.google.com/search/reference/robots_meta_tag
###

# All is default and essentially has no effect.
set $robots_header "all";

if ($host ~* ^(?!www\.govcms\.gov\.au$)(?:[\w\-]+\.)+govcms\.gov\.au$){
# None = noindex, nofollow.
set $robots_header "none";
}

add_header X-Robots-Tag $robots_header;
2 changes: 2 additions & 0 deletions .docker/images/nginx/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
.phpunit*
52 changes: 52 additions & 0 deletions .docker/images/nginx/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* PHPUnit Bootstrap file.
*/

include_once __DIR__ . '/vendor/autoload.php';

function get_curl_headers($path = "/", $opts = NULL) {
$uri = getenv('LOCALDEV_URL') ?: 'http://nginx:8080';

$response = null;

$path = '/' . ltrim($path, '/');

exec("docker-compose exec -T test curl {$uri}{$path} -I {$opts} 2>/dev/null", $response);

if (empty($response)) {
return [];
}

$response = array_map('trim', $response);

foreach ($response as $line) {
if (strpos($line, 'HTTP') !== false) {
$part = explode(' ', $line);
$headers['Status'] = trim($part[1]);
continue;
}
$part = explode(':', $line);
if (count($part) == 2) {
$headers[$part[0]] = trim($part[1]);
}
}

return $headers;
}

function curl_get_content($path = "/", $opts = NULL) {
$uri = getenv('LOCALDEV_URL') ?: 'http://nginx:8080';

$response = null;
$path = '/' . ltrim($path, '/');

exec("docker-compose exec -T test curl {$uri}{$path} {$opts} 2>/dev/null", $response);

if (empty($response)) {
return FALSE;
}

return $response;
}
19 changes: 19 additions & 0 deletions .docker/images/nginx/tests/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "govcmstests/nginx",
"description": "Testing framework for the nginx image.",
"type": "project",
"authors": [
{
"name": "Steve Worley",
"email": "[email protected]"
}
],
"require": {
"phpunit/phpunit": "^7.5"
},
"autoload": {
"psr-4": {
"GovCMSTests\\": "src/"
}
}
}
Loading

0 comments on commit a7031b3

Please sign in to comment.