Skip to content
Permalink
Browse files
Fix failing tests caused by Android's whitelist behaviour change
  • Loading branch information
agrieve committed Mar 4, 2015
1 parent 370f7b3 commit 7ad3e7572f1887bd8410a8b3ae15abb0ad6d35f7
Showing 6 changed files with 70 additions and 31 deletions.
@@ -38,6 +38,7 @@
<allow-intent href="mailto:*" />
<allow-intent href="tel:*" />
<allow-intent href="www.google.com" />
<allow-navigation href="data:*" />
<platform name="blackberry10">
<access origin="file:///" />
<access origin="https://www.apache.org" />
@@ -0,0 +1,33 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.cordova.mobilespec;

import android.net.Uri;

import org.apache.cordova.CordovaPlugin;

public class AndroidMobileSpecTestPlugin extends CordovaPlugin {
@Override
public Uri remapUri(Uri uri) {
if ("stealbridgesecret.test".equals(uri.getHost())) {
return Uri.parse("data:text/html,");
}
return null;
}
}
@@ -46,4 +46,14 @@

<js-module src="tests/input.tests.js" name="input.tests">
</js-module>

<platform name="android">
<source-file src="AndroidMobileSpecTestPlugin.java" target-dir="src/org/apache/cordova/mobilespec" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="org.apache.cordova.mobilespec.tests" >
<param name="android-package" value="org.apache.cordova.mobilespec.AndroidMobileSpecTestPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>
</platform>
</plugin>
@@ -20,20 +20,27 @@
*/
exports.defineAutoTests = function () {
describe('Bridge', function (done) {
var frame;
afterEach(function () {
if (frame) {
document.body.removeChild(frame);
}
});
it("bridge.spec.1 should reject bridge from iframe with data: URL", function (done) {
if (cordova.platformId != 'android') {
pending();
return;
}
var ifr = document.createElement('iframe');
frame = document.createElement('iframe');

ifr.src = 'data:text/html,';
ifr.onload = function () {
var stolenSecret = ifr.contentWindow.prompt('', 'gap_init:');
// Gets intercepted in native.
frame.src = 'http://stealbridgesecret.test/';
frame.onload = function () {
var stolenSecret = frame.contentWindow.prompt('', 'gap_init:');
expect(!!stolenSecret).toBe(false);
done();
};
document.body.appendChild(ifr);
document.body.appendChild(frame);
});

});
}
@@ -22,31 +22,20 @@ exports.defineAutoTests = function () {
var isWindows = (cordova.platformId === "windows") || (cordova.platformId === "windows8");

describe('data uris', function () {
var gotFoo = false,
onMessageBind,
originalTimeout;
var frame;
var onMessageBind;

function onMessage (done, msg) {
gotFoo = gotFoo || msg.data == 'foo';
if (gotFoo) {
expect(gotFoo).toBe(true);
if (typeof(done) === 'function') {
done();
}
function onMessage(done, msg) {
if (msg.data == 'foo') {
done();
}
};

beforeEach(function () {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
});
}

afterEach(function () {
if (this.frame) {
document.body.removeChild(this.frame);
if (frame) {
document.body.removeChild(frame);
window.removeEventListener('message', onMessageBind, false);
}
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it("datauri.spec.1 should work with iframes", function (done) {
@@ -58,13 +47,12 @@ exports.defineAutoTests = function () {
pending();
}

this.frame = document.createElement('iframe');

frame = document.createElement('iframe');
onMessageBind = onMessage.bind(null, done);
window.addEventListener('message', onMessageBind, false);
this.frame.src = 'data:text/html;charset=utf-8,%3Chtml%3E%3Cscript%3Eparent.postMessage%28%27foo%27%2C%27%2A%27%29%3C%2Fscript%3E%3C%2Fhtml%3E';
document.body.appendChild(this.frame);
}, 'iframe did not load.');
frame.src = 'data:text/html;charset=utf-8,%3Chtml%3E%3Cscript%3Eparent.postMessage%28%27foo%27%2C%27%2A%27%29%3C%2Fscript%3E%3C%2Fhtml%3E';
document.body.appendChild(frame);
}, 1000);
});

describe('data uris', function () {
@@ -200,7 +200,7 @@ exports.defineAutoTests = function () {
itShouldReject('http://www.apache.org:pass@evil.com/');
itShouldReject('http://www.apache.org.evil.com/');
itShouldAccept('file:///foo');
itShouldAccept('content:///foo');
itShouldReject('content:///foo');
});
});
}

0 comments on commit 7ad3e75

Please sign in to comment.