@polymer/platinum-https-redirect
Version:
Force a redirect to HTTPS when not on a local web server.
67 lines (59 loc) • 2.36 kB
HTML
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../platinum-https-redirect.html">
</head>
<body>
<script>
suite('<platinum-https-redirect>', function() {
document.addEventListener('WebComponentsReady', function() {
var platinumHttpsRedirect = document.createElement('platinum-https-redirect');
test('_isLocalhost(valid) results in true', function() {
var validLocalhostValues = [
'localhost',
'127.0.0.1',
'127.255.255.255',
'[::1]'
];
validLocalhostValues.forEach(function(hostname) {
// Check for explicit true and not just truthiness.
assert.strictEqual(platinumHttpsRedirect._isLocalhost(hostname), true,
hostname + ' should be considered localhost');
});
});
test('_isLocalhost(invalid) results in false', function() {
var invalidLocalhostValues = [
'',
'example.com',
'localhost.net',
'ocalhost',
'127.256.256.256',
'::1',
'[::2]',
'[::',
'192.168.1.1'
];
invalidLocalhostValues.forEach(function(hostname) {
// Check for explicit false and not just falsiness.
assert.strictEqual(platinumHttpsRedirect._isLocalhost(hostname), false,
hostname + ' should not be considered localhost');
});
});
});
});
</script>
</body>
</html>