Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38b84be

Browse files
committed
[#2] Implemented initial Travis tests
1 parent ae245b9 commit 38b84be

File tree

4 files changed

+180
-1
lines changed

4 files changed

+180
-1
lines changed

.travis.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# @file
2+
# .travis.yml - Drupal Paranoia.
3+
4+
language: php
5+
6+
## Run on container environment
7+
sudo: false
8+
9+
php:
10+
- 7.1
11+
12+
matrix:
13+
fast_finish: true
14+
15+
env:
16+
global:
17+
- SITE_NAME="mysite"
18+
- SITE_ROOT="$TRAVIS_BUILD_DIR/../$SITE_NAME"
19+
20+
before_install:
21+
# Disable xdebug.
22+
- phpenv config-rm xdebug.ini
23+
24+
# Update Composer.
25+
- composer self-update --stable
26+
- composer clear-cache
27+
28+
# Install composer parallel install plugin.
29+
- composer global require hirak/prestissimo --no-interaction
30+
31+
install:
32+
# Create Drupal project.
33+
- composer create-project drupal-composer/drupal-project:8.x-dev --stability dev --no-interaction --no-dev --prefer-dist -vvv "$SITE_ROOT" || exit 1
34+
35+
# https://github.com/drupal-composer/drupal-paranoia#configuration
36+
- cd "$SITE_ROOT"; mv "$SITE_ROOT/web" "$SITE_ROOT/app"
37+
- sed -e "s?web/?app/?g" --in-place "$SITE_ROOT/composer.json"
38+
- cd "$SITE_ROOT"; composer config extra.drupal-app-dir app
39+
- cd "$SITE_ROOT"; composer config extra.drupal-web-dir web
40+
41+
# Require local drupal-paranoia project.
42+
- cd "$SITE_ROOT"; composer config repositories.local_drupal_paranoia path "$TRAVIS_BUILD_DIR"
43+
- cd "$SITE_ROOT"; composer require --update-no-dev drupal-composer/drupal-paranoia:"*" -vvv || exit 1
44+
45+
script:
46+
# Run test script.
47+
- $TRAVIS_BUILD_DIR/.travis/test-script.sh

.travis/test-script.sh

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/bash
2+
3+
SITE_WEB="$SITE_ROOT/web"
4+
SITE_APP="$SITE_ROOT/app"
5+
6+
# Colors.
7+
RED=$'\E[1;31m'
8+
GREEN=$'\E[1;32m'
9+
BLUE=$'\E[1;34m'
10+
11+
# Message status.
12+
COLOR_RESET=$'\E[0m'
13+
MSG_ERROR="${RED}[ERROR]${COLOR_RESET}"
14+
MSG_OK="${GREEN}[OK]${COLOR_RESET}"
15+
MSG_INFO="${BLUE}[INFO]${COLOR_RESET}"
16+
17+
##
18+
# Check if the "app" folder exists.
19+
#
20+
if [ ! -d "$SITE_APP" ]; then
21+
echo "${MSG_ERROR} 'app' folder does not exist"
22+
exit 1
23+
else
24+
echo "${MSG_OK} 'app' folder exists"
25+
fi
26+
27+
##
28+
# Check if the "web" folder exists.
29+
#
30+
if [ ! -d "$SITE_WEB" ]; then
31+
echo "${MSG_ERROR} 'web' folder does not exist"
32+
exit 1
33+
else
34+
echo "${MSG_OK} 'web' folder exists"
35+
fi
36+
37+
##
38+
# Check if the stub files exist.
39+
# See \DrupalComposer\DrupalParanoia $frontControllers
40+
#
41+
STUB_FILES=(
42+
"web/index.php"
43+
"web/core/install.php"
44+
"web/core/rebuild.php"
45+
"web/core/modules/statistics/statistics.php"
46+
)
47+
48+
for STUB_FILE_PATH in ${STUB_FILES[*]}; do
49+
if [ ! -f "$STUB_FILE_PATH" ]; then
50+
echo "${MSG_ERROR} stub file '$STUB_FILE_PATH' does not exist"
51+
exit 1
52+
else
53+
echo "${MSG_OK} stub file '$STUB_FILE_PATH' exists"
54+
fi
55+
56+
# Check if the stub file has the correct code.
57+
STUB_FILE=$( basename "$STUB_FILE_PATH" )
58+
if [ $( grep -c "require './$STUB_FILE';" "$STUB_FILE_PATH" ) -eq 0 ]; then
59+
echo "${MSG_ERROR} stub file '$STUB_FILE_PATH' does not contain the correct content"
60+
exit 1
61+
else
62+
echo "${MSG_OK} stub file '$STUB_FILE_PATH' contains the correct content"
63+
fi
64+
done
65+
66+
##
67+
# Check if there are no PHP files in the "web" folder.
68+
# It is ignoring the stub files.
69+
#
70+
if [ $( grep -Rl "<?php" "$SITE_WEB" | awk '{print $0" "}' | tr -d '\n' | grep -vc "$SITE_WEB/index.php $SITE_WEB/core/install.php $SITE_WEB/core/rebuild.php $SITE_WEB/core/modules/statistics/statistics.php" ) -eq 1 ]; then
71+
grep -Rl "<?php" "$SITE_WEB"
72+
echo "${MSG_ERROR} there are PHP files (non-stub files) in the web directory"
73+
exit 1
74+
else
75+
echo "${MSG_OK} there are no PHP files (non-stub files) in the web directory"
76+
fi
77+
78+
##
79+
# Install a Drupal package using Composer and check if the package's assets have been symlinked.
80+
#
81+
echo "${MSG_INFO} installing 'drupal/bootstrap' to check if the theme assets will be symlinked to web directory"
82+
cd "$SITE_ROOT"
83+
composer require --update-no-dev drupal/bootstrap || exit 1
84+
85+
BOOTSTRAP_SYMLINK="$SITE_WEB/themes/contrib/bootstrap/screenshot.png"
86+
if [ ! -L "$BOOTSTRAP_SYMLINK" ]; then
87+
echo "${MSG_ERROR} '$BOOTSTRAP_SYMLINK' does not exist or it is not a symlink"
88+
exit 1
89+
else
90+
echo "${MSG_OK} $BOOTSTRAP_SYMLINK has been symlinked"
91+
fi
92+
93+
##
94+
# Remove the Drupal package using "composer remove" and check if the package's assets have been removed from the "web" directory.
95+
#
96+
echo "${MSG_INFO} removing 'drupal/bootstrap' to check if the theme's assets will be removed from the web directory"
97+
98+
composer remove drupal/bootstrap || exit 1
99+
100+
if [ -d "$SITE_WEB/themes/contrib/bootstrap" ]; then
101+
echo "${MSG_ERROR} the 'drupal/bootstrap' assets still exist in the web directory after the package has been removed"
102+
exit 1
103+
else
104+
echo "${MSG_OK} 'drupal/bootstrap' assets have been removed from the web directory"
105+
fi
106+
107+
##
108+
# Create a theme image, run the command 'composer drupal:paranoia' and check if the image has been symlinked.
109+
#
110+
touch "$SITE_APP/themes/travis-test-image.jpg"
111+
112+
# Rebuild web directory.
113+
composer drupal:paranoia || exit 1
114+
115+
if [ ! -L "$SITE_WEB/themes/travis-test-image.jpg" ]; then
116+
echo "${MSG_ERROR} 'composer drupal:paranoia' command did not re-create the web directory with new symlinks"
117+
exit 1
118+
else
119+
echo "${MSG_OK} 'composer drupal:paranoia' command re-created the web directory with new symlinks"
120+
fi

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog: Drupal Paranoia
2+
3+
## Releases
4+
5+
### 1.0.0-alpha2, 2018-04-18
6+
- [#2] Exposed the plugin as custom command - drupal:paranoia.
7+
- Implemented initial Travis tests.
8+
9+
### 1.0.0-alpha1, 2018-04-11
10+
- Initial release.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
[![Build Status](https://travis-ci.org/drupal-composer/drupal-paranoia.svg?branch=1.x)](https://travis-ci.org/drupal-composer/drupal-paranoia)
2+
13
# Drupal Paranoia
24
Composer plugin for improving the website security for composer-based Drupal websites by moving all __PHP files out of docroot__.
35

46
## Why use this Plugin?
5-
The critical security issue with [Coder](https://www.drupal.org/project/coder) is a good example to consider moving PHP files outside of docroot:
7+
The critical security issue with [Coder](https://www.drupal.org/project/coder) is a good example to consider moving PHP files outside of docroot:
68
- [Remote Code Execution - SA-CONTRIB-2016-039](https://www.drupal.org/node/2765575)
79
- https://twitter.com/drupalsecurity/status/753263548458004480
810

0 commit comments

Comments
 (0)