mirror of https://github.com/xwiki-labs/cryptpad
more tests for the checkup page
This commit is contained in:
parent
436f1d55c9
commit
c84ecbabc0
|
@ -0,0 +1,57 @@
|
|||
@import (reference) "../include/colortheme-all.less";
|
||||
@import (reference) "../include/font.less";
|
||||
//@import (reference) "../include/forms.less";
|
||||
@import (reference) "../include/alertify.less";
|
||||
|
||||
html, body {
|
||||
.font_main();
|
||||
.alertify_main();
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
background-color: @cp_static-bg !important;
|
||||
color: @cryptpad_text_col;
|
||||
font-family: "IBM Plex Mono";
|
||||
|
||||
.report {
|
||||
font-size: 30px;
|
||||
max-width: 50%;
|
||||
margin: auto;
|
||||
padding-top: 15px;
|
||||
}
|
||||
|
||||
.success {
|
||||
border: 1px solid green;
|
||||
}
|
||||
.failure {
|
||||
border: 1px solid red;
|
||||
}
|
||||
.error {
|
||||
border: 1px solid red;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.failures div.error, .summary {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
table {
|
||||
td {
|
||||
padding: 5px;
|
||||
border: 1px solid white;
|
||||
}
|
||||
}
|
||||
|
||||
.advisory-text {
|
||||
display: inline-block;
|
||||
word-break: break-all;
|
||||
padding: 5px;
|
||||
//font-size: 16px;
|
||||
border: 1px solid red;
|
||||
background-color: @cp_alerts-danger-bg;
|
||||
color: @cp_alerts-danger-text;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,26 +4,6 @@
|
|||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<script data-bootload="main.js" data-main="/common/boot.js" src="/bower_components/requirejs/require.js"></script>
|
||||
|
||||
<style>
|
||||
.report {
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
.success {
|
||||
border: 3px solid green;
|
||||
}
|
||||
.failure {
|
||||
border: 3px solid red;
|
||||
}
|
||||
.error {
|
||||
border: 1px solid red;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
|
|
@ -4,25 +4,74 @@ define([
|
|||
'/assert/assertions.js',
|
||||
'/common/hyperscript.js',
|
||||
'/customize/messages.js',
|
||||
'/common/sframe-common-outer.js',
|
||||
|
||||
|
||||
'/bower_components/tweetnacl/nacl-fast.min.js',
|
||||
'less!/customize/src/less2/pages/page-assert.less',
|
||||
], function ($, ApiConfig, Assertions, h, Messages) {
|
||||
'less!/customize/src/less2/pages/page-checkup.less',
|
||||
], function ($, ApiConfig, Assertions, h, Messages, SFCommonO) {
|
||||
var assert = Assertions();
|
||||
|
||||
assert(function (cb) {
|
||||
var c = ApiConfig;
|
||||
cb(Boolean(c.httpUnsafeOrigin && c.httpSafeOrigin));
|
||||
}, "Sandbox configuration: ensure that both httpUnsafeOrigin and httpSafeOrigin are defined"); // XXX
|
||||
var trimSlashes = function (s) {
|
||||
if (typeof(s) !== 'string') { return s; }
|
||||
return s.replace(/\/+$/, '');
|
||||
};
|
||||
|
||||
var _alert = function (content) {
|
||||
return h('span.advisory-text', content);
|
||||
};
|
||||
|
||||
var trimmedSafe = trimSlashes(ApiConfig.httpSafeOrigin);
|
||||
var trimmedUnsafe = trimSlashes(ApiConfig.httpUnsafeOrigin);
|
||||
|
||||
assert(function (cb) {
|
||||
var c = ApiConfig;
|
||||
return void cb(c.httpUnsafeOrigin !== c.httpSafeOrigin);
|
||||
}, 'Sandbox configuration: httpUnsafeOrigin !== httpSafeOrigin'); // XXX
|
||||
//console.error(trimmedSafe, trimmedUnsafe);
|
||||
cb(Boolean(trimmedSafe && trimmedUnsafe));
|
||||
}, _alert("Sandbox configuration: ensure that both httpUnsafeOrigin and httpSafeOrigin are defined"));
|
||||
|
||||
assert(function (cb) {
|
||||
return void cb(trimmedSafe !== trimmedUnsafe);
|
||||
}, _alert('Sandbox configuration: httpUnsafeOrigin !== httpSafeOrigin'));
|
||||
|
||||
assert(function (cb) {
|
||||
cb((window.location.origin + '/') === ApiConfig.httpUnsafeOrigin);
|
||||
}, 'Sandbox configuration: loading via httpUnsafeOrigin'); // XXX
|
||||
}, _alert('Sandbox configuration: loading via httpUnsafeOrigin'));
|
||||
|
||||
|
||||
var checkAvailability = function (url, cb) {
|
||||
$.ajax({
|
||||
url: url,
|
||||
date: {},
|
||||
complete: function (xhr) {
|
||||
cb(xhr.status === 200);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
assert(function (cb) {
|
||||
checkAvailability(trimmedUnsafe, cb);
|
||||
}, _alert("Main domain is not available"));
|
||||
|
||||
assert(function (cb) {
|
||||
console.log(trimmedSafe);
|
||||
checkAvailability(trimmedSafe, cb);
|
||||
}, _alert("Sandbox domain is not available")); // XXX Blocked by CSP. try loading it via sframe ?
|
||||
|
||||
var row = function (cells) {
|
||||
return h('tr', cells.map(function (cell) {
|
||||
return h('td', cell);
|
||||
}));
|
||||
};
|
||||
|
||||
var failureReport = function (obj) {
|
||||
return h('div.error', [
|
||||
h('h5', obj.message),
|
||||
h('table', [
|
||||
row(["Failed test number", obj.test + 1]),
|
||||
row(["Returned value", obj.output]),
|
||||
]),
|
||||
]);
|
||||
};
|
||||
|
||||
assert.run(function (state) {
|
||||
var errors = state.errors;
|
||||
|
@ -31,19 +80,20 @@ define([
|
|||
Messages.assert_numberOfTestsPassed = "{0} / {1} tests passed.";
|
||||
|
||||
var statusClass = failed? 'failure': 'success';
|
||||
$('body').prepend(h('div.report.' + statusClass, [
|
||||
Messages._getKey('assert_numberOfTestsPassed', [
|
||||
|
||||
var summary = h('div.summary.' + statusClass, [
|
||||
h('p', Messages._getKey('assert_numberOfTestsPassed', [
|
||||
state.passed,
|
||||
state.total
|
||||
]),
|
||||
h('div.failures', errors.map(function (obj) {
|
||||
return h('p.error', [
|
||||
h('p', "Test number: " + obj.test),
|
||||
h('p', "Error message: " + obj.message),
|
||||
h('p', "Returned value: " + obj.output),
|
||||
h('br'),
|
||||
])),
|
||||
h('p', "Details found below"),
|
||||
]);
|
||||
})),
|
||||
]));
|
||||
|
||||
var report = h('div.report', [
|
||||
summary,
|
||||
h('div.failures', errors.map(failureReport)),
|
||||
]);
|
||||
|
||||
$('body').prepend(report);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue