Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving an issue in php run images by allowing casing in php file extension #352

Merged
merged 10 commits into from
Sep 17, 2019
Merged
2 changes: 1 addition & 1 deletion build/__phpVersions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file was auto-generated from 'constants.yaml'. Changes may be overridden.

PHP_BUILD_BASE_TAG='20190802.1'
PHP_RUNTIME_BASE_TAG='20190906.21'
PHP_RUNTIME_BASE_TAG='20190917.1'
COMPOSER_VERSION='1.8.6'
COMPOSER_SHA384='a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1'
PHP73_VERSION='7.3.5'
Expand Down
2 changes: 1 addition & 1 deletion build/constants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
- name: php-versions
constants:
php-build-base-tag: 20190802.1
php-runtime-base-tag: 20190906.21
php-runtime-base-tag: 20190917.1
composer-version: 1.8.6
composer-sha384: a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1
# hashes are for .tar.xz
Expand Down
5 changes: 5 additions & 0 deletions images/runtime/php/Dockerfile.base.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ ENV APACHE_PORT 8080
RUN sed -ri -e 's!<VirtualHost \*:80>!<VirtualHost *:${APACHE_PORT}>!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!<VirtualHost _default_:443>!<VirtualHost _default_:${APACHE_PORT}>!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!Listen 80!Listen ${APACHE_PORT}!g' /etc/apache2/ports.conf
# Edit Configuration to instruct Apache on how to process PHP files
RUN echo -e '<FilesMatch "\.(?i:ph([[p]?[0-9]*|tm[l]?))$">\n SetHandler application/x-httpd-php\n</FilesMatch>' >> /etc/apache2/apache2.conf
# Disable Apache2 server signature
RUN echo -e 'ServerSignature Off' >> /etc/apache2/apache2.conf
RUN echo -e 'ServerTokens Prod' >> /etc/apache2/apache2.conf

# Install common PHP extensions
RUN apt-get update \
Expand Down
2 changes: 1 addition & 1 deletion src/BuildScriptGenerator/PhpVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Oryx.Common
public static class PhpVersions
{
public const string PhpBuildBaseTag = "20190802.1";
public const string PhpRuntimeBaseTag = "20190906.21";
public const string PhpRuntimeBaseTag = "20190917.1";
public const string ComposerVersion = "1.8.6";
public const string ComposerSha384 = "a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1";
public const string Php73Version = "7.3.5";
Expand Down
95 changes: 93 additions & 2 deletions tests/Oryx.RuntimeImage.Tests/Php/PhpImageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,34 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Oryx.RuntimeImage.Tests
{
public class PhpImageTest : TestBase
public class PhpTestBase : TestBase, IClassFixture<TestTempDirTestFixture>
{
public PhpImageTest(ITestOutputHelper output) : base(output)
public readonly string _hostSamplesDir;
public readonly string _tempRootDir;
public readonly HttpClient _httpClient = new HttpClient();

public DockerVolume CreateSampleAppVolume(string sampleAppName) =>
DockerVolume.CreateMirror(Path.Combine(_hostSamplesDir, "php", sampleAppName));

public PhpTestBase(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) : base(output)
{
_hostSamplesDir = Path.Combine(Directory.GetCurrentDirectory(), "SampleApps");
_tempRootDir = testTempDirTestFixture.RootDirPath;
}
}

public class PhpImageTest : PhpTestBase
{
public PhpImageTest(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) : base(output, testTempDirTestFixture)
{
}

Expand Down Expand Up @@ -65,6 +85,77 @@ public void GraphicsExtension_Gd_IsInstalled(string imageTag)
Assert.True((bool)((JValue)gdInfo.GetValue("PNG Support")).Value);
}

[Theory]
[InlineData("7.3")]
[InlineData("7.2")]
[InlineData("7.0")]
[InlineData("5.6")]
public async Task Check_If_Apache_Allows_Casing_In_PHP_File_Extension(string imageTag)
arroyc marked this conversation as resolved.
Show resolved Hide resolved
{
// Arrange
var appName = "imagick-example";
var hostDir = Path.Combine(_hostSamplesDir, "php", appName);
var volume = CreateSampleAppVolume(hostDir);
var appDir = volume.ContainerDir;

var testSiteConfigApache2 =
@"<VirtualHost *:80>
\nServerAdmin php-x@localhost
\nDocumentRoot /var/www/php-x/
\nServerName localhost
\nServerAlias www.php-x.com

\n<Directory />
\n Options FollowSymLinks
\n AllowOverride None
\n</Directory>
\n<Directory /var/www/php-x/>
Require all granted
\n</Directory>

\nErrorLog /var/www/php-x/error.log
\nCustomLog /var/www/php-x/access.log combined
</VirtualHost>";

int containerPort = 8080;
var customSiteConfig = @"echo '" + testSiteConfigApache2 + "' > /etc/apache2/sites-available/php-x.conf";
var portConfig = @"sed -i -e 's!\${APACHE_PORT}!" + containerPort + "!g' /etc/apache2/ports.conf /etc/apache2/sites-available/*.conf";
var documentRootConfig = @"sed -i -e 's!\${APACHE_DOCUMENT_ROOT}!/var/www/php-x/!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf /etc/apache2/sites-available/*.conf";
var script = new ShellScriptBuilder()
.AddCommand("mkdir -p /var/www/php-x")
.AddCommand("echo '' > /var/www/php-x/error.log")
.AddCommand("echo '' > /var/www/php-x/access.log")
.AddCommand("echo '<?php\n phpinfo();\n ?>' > /var/www/php-x/inDex.PhP")
.AddCommand("chmod -R +x /var/www/php-x")
.AddCommand(documentRootConfig)
.AddCommand(portConfig)
.AddCommand("echo 'ServerName localhost' >> /etc/apache2/apache2.conf")
.AddCommand(customSiteConfig)
.AddCommand("a2ensite php-x.conf") // load custom site
.AddCommand("service apache2 restart") // start apache with the custom site configuration
.AddCommand("tail -f /dev/null") //foreground process to keep the container alive
.ToString();

// Assert
await EndToEndTestHelper.RunAndAssertAppAsync(
imageName: $"oryxdevmcr.azurecr.io/public/oryx/php-{imageTag}",
output: _output,
volumes: new List<DockerVolume> { volume },
environmentVariables: null,
port: containerPort,
link: null,
runCmd: "/bin/sh",
runArgs: new[] { "-c", script },
assertAction: async (hostPort) =>
{
var data = await _httpClient.GetStringAsync($"http://localhost:{hostPort}/inDex.PhP");
Assert.DoesNotContain("<?", data);
Assert.DoesNotContain("<?php", data);
Assert.DoesNotContain("?>", data);
},
dockerCli: _dockerCli);
}

[Theory]
[InlineData("7.0")]
[InlineData("5.6")]
Expand Down