1
0

setupchecksSpec.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. /**
  2. * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. describe('OC.SetupChecks tests', function() {
  11. var suite = this;
  12. var protocolStub;
  13. beforeEach( function(){
  14. protocolStub = sinon.stub(OC, 'getProtocol');
  15. suite.server = sinon.fakeServer.create();
  16. });
  17. afterEach( function(){
  18. suite.server.restore();
  19. protocolStub.restore();
  20. });
  21. describe('checkWebDAV', function() {
  22. it('should fail with another response status code than 201 or 207', function(done) {
  23. var async = OC.SetupChecks.checkWebDAV();
  24. suite.server.requests[0].respond(200);
  25. async.done(function( data, s, x ){
  26. expect(data).toEqual([{
  27. msg: 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.',
  28. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  29. }]);
  30. done();
  31. });
  32. });
  33. it('should return no error with a response status code of 207', function(done) {
  34. var async = OC.SetupChecks.checkWebDAV();
  35. suite.server.requests[0].respond(207);
  36. async.done(function( data, s, x ){
  37. expect(data).toEqual([]);
  38. done();
  39. });
  40. });
  41. it('should return no error with a response status code of 401', function(done) {
  42. var async = OC.SetupChecks.checkWebDAV();
  43. suite.server.requests[0].respond(401);
  44. async.done(function( data, s, x ){
  45. expect(data).toEqual([]);
  46. done();
  47. });
  48. });
  49. });
  50. describe('checkWellKnownUrl', function() {
  51. it('should fail with another response status code than the expected one', function(done) {
  52. var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);
  53. suite.server.requests[0].respond(200);
  54. async.done(function( data, s, x ){
  55. expect(data).toEqual([{
  56. msg: 'Your web server is not properly set up to resolve "/.well-known/caldav". Further information can be found in the <a target="_blank" rel="noreferrer noopener" class="external" href="http://example.org/admin-setup-well-known-URL">documentation ↗</a>.',
  57. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  58. }]);
  59. done();
  60. });
  61. });
  62. it('should return no error with the expected response status code', function(done) {
  63. var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);
  64. suite.server.requests[0].respond(207);
  65. async.done(function( data, s, x ){
  66. expect(data).toEqual([]);
  67. done();
  68. });
  69. });
  70. it('should return no error with the default expected response status code', function(done) {
  71. var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', true);
  72. suite.server.requests[0].respond(207);
  73. async.done(function( data, s, x ){
  74. expect(data).toEqual([]);
  75. done();
  76. });
  77. });
  78. it('should return no error when no check should be run', function(done) {
  79. var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', false);
  80. async.done(function( data, s, x ){
  81. expect(data).toEqual([]);
  82. done();
  83. });
  84. });
  85. });
  86. describe('checkProviderUrl', function() {
  87. it('should fail with another response status code than the expected one', function(done) {
  88. var async = OC.SetupChecks.checkProviderUrl('/ocm-provider/', 'http://example.org/PLACEHOLDER', true);
  89. suite.server.requests[0].respond(302);
  90. async.done(function( data, s, x ){
  91. expect(data).toEqual([{
  92. msg: 'Your web server is not properly set up to resolve "/ocm-provider/". This is most likely related to a web server configuration that was not updated to deliver this folder directly. Please compare your configuration against the shipped rewrite rules in ".htaccess" for Apache or the provided one in the documentation for Nginx at it\'s <a target="_blank" rel="noreferrer noopener" class="external" href="http://example.org/admin-nginx">documentation page ↗</a>. On Nginx those are typically the lines starting with "location ~" that need an update.',
  93. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  94. }]);
  95. done();
  96. });
  97. });
  98. it('should return no error with the expected response status code', function(done) {
  99. var async = OC.SetupChecks.checkProviderUrl('/ocm-provider/', 'http://example.org/PLACEHOLDER', true);
  100. suite.server.requests[0].respond(200);
  101. async.done(function( data, s, x ){
  102. expect(data).toEqual([]);
  103. done();
  104. });
  105. });
  106. it('should return no error when no check should be run', function(done) {
  107. var async = OC.SetupChecks.checkProviderUrl('/ocm-provider/', 'http://example.org/PLACEHOLDER', false);
  108. async.done(function( data, s, x ){
  109. expect(data).toEqual([]);
  110. done();
  111. });
  112. });
  113. });
  114. describe('checkWOFF2Loading', function() {
  115. it('should fail with another response status code than the expected one', function(done) {
  116. var async = OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/NotoSans-Regular-latin.woff2'), 'http://example.org/PLACEHOLDER');
  117. suite.server.requests[0].respond(302);
  118. async.done(function( data, s, x ){
  119. expect(data).toEqual([{
  120. msg: 'Your web server is not properly set up to deliver .woff2 files. This is typically an issue with the Nginx configuration. For Nextcloud 15 it needs an adjustement to also deliver .woff2 files. Compare your Nginx configuration to the recommended configuration in our <a target="_blank" rel="noreferrer noopener" class="external" href="http://example.org/admin-nginx">documentation ↗</a>.',
  121. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  122. }]);
  123. done();
  124. });
  125. });
  126. it('should return no error with the expected response status code', function(done) {
  127. var async = OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/NotoSans-Regular-latin.woff2'), 'http://example.org/PLACEHOLDER');
  128. suite.server.requests[0].respond(200);
  129. async.done(function( data, s, x ){
  130. expect(data).toEqual([]);
  131. done();
  132. });
  133. });
  134. });
  135. describe('checkDataProtected', function() {
  136. oc_dataURL = "data";
  137. it('should return an error if data directory is not protected', function(done) {
  138. var async = OC.SetupChecks.checkDataProtected();
  139. suite.server.requests[0].respond(200, {'Content-Type': 'text/plain'}, '');
  140. async.done(function( data, s, x ){
  141. expect(data).toEqual([
  142. {
  143. msg: 'Your data directory and files are probably accessible from the internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.',
  144. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  145. }]);
  146. done();
  147. });
  148. });
  149. it('should not return an error if data directory is protected', function(done) {
  150. var async = OC.SetupChecks.checkDataProtected();
  151. suite.server.requests[0].respond(403);
  152. async.done(function( data, s, x ){
  153. expect(data).toEqual([]);
  154. done();
  155. });
  156. });
  157. it('should return an error if data directory is a boolean', function(done) {
  158. oc_dataURL = false;
  159. var async = OC.SetupChecks.checkDataProtected();
  160. async.done(function( data, s, x ){
  161. expect(data).toEqual([]);
  162. done();
  163. });
  164. });
  165. });
  166. describe('checkSetup', function() {
  167. it('should return an error if server has no internet connection', function(done) {
  168. var async = OC.SetupChecks.checkSetup();
  169. suite.server.requests[0].respond(
  170. 200,
  171. {
  172. 'Content-Type': 'application/json'
  173. },
  174. JSON.stringify({
  175. reverseProxyGeneratedURL: 'https://server',
  176. generic: {
  177. network: {
  178. "Internet connectivity": {
  179. severity: "warning",
  180. description: 'This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.',
  181. linkToDoc: null
  182. }
  183. },
  184. },
  185. })
  186. );
  187. async.done(function( data, s, x ){
  188. expect(data).toEqual([
  189. {
  190. msg: 'This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.',
  191. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  192. },
  193. ]);
  194. done();
  195. });
  196. });
  197. it('should return an error if server has no internet connection and data directory is not protected', function(done) {
  198. var async = OC.SetupChecks.checkSetup();
  199. suite.server.requests[0].respond(
  200. 200,
  201. {
  202. 'Content-Type': 'application/json'
  203. },
  204. JSON.stringify({
  205. reverseProxyGeneratedURL: 'https://server',
  206. generic: {
  207. network: {
  208. "Internet connectivity": {
  209. severity: "warning",
  210. description: 'This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.',
  211. linkToDoc: null
  212. }
  213. },
  214. },
  215. })
  216. );
  217. async.done(function( data, s, x ){
  218. expect(data).toEqual([
  219. {
  220. msg: 'This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.',
  221. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  222. },
  223. ]);
  224. done();
  225. });
  226. });
  227. it('should return an error if server has no internet connection and data directory is not protected and memcache is available', function(done) {
  228. var async = OC.SetupChecks.checkSetup();
  229. suite.server.requests[0].respond(
  230. 200,
  231. {
  232. 'Content-Type': 'application/json',
  233. },
  234. JSON.stringify({
  235. reverseProxyGeneratedURL: 'https://server',
  236. generic: {
  237. network: {
  238. "Internet connectivity": {
  239. severity: "warning",
  240. description: 'This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.',
  241. linkToDoc: null
  242. }
  243. },
  244. },
  245. })
  246. );
  247. async.done(function( data, s, x ){
  248. expect(data).toEqual([
  249. {
  250. msg: 'This server has no working internet connection: Multiple endpoints could not be reached. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. Establish a connection from this server to the internet to enjoy all features.',
  251. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  252. }
  253. ]);
  254. done();
  255. });
  256. });
  257. it('should return a warning if the memory limit is below the recommended value', function(done) {
  258. var async = OC.SetupChecks.checkSetup();
  259. suite.server.requests[0].respond(
  260. 200,
  261. {
  262. 'Content-Type': 'application/json',
  263. },
  264. JSON.stringify({
  265. reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
  266. reverseProxyGeneratedURL: 'https://server',
  267. generic: {
  268. network: {
  269. "Internet connectivity": {
  270. severity: "success",
  271. description: null,
  272. linkToDoc: null
  273. }
  274. },
  275. php: {
  276. "Internet connectivity": {
  277. severity: "success",
  278. description: null,
  279. linkToDoc: null
  280. },
  281. "PHP memory limit": {
  282. severity: "error",
  283. description: "The PHP memory limit is below the recommended value of 512MB.",
  284. linkToDoc: null
  285. },
  286. },
  287. },
  288. })
  289. );
  290. async.done(function( data, s, x ){
  291. expect(data).toEqual([{
  292. msg: 'The PHP memory limit is below the recommended value of 512MB.',
  293. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  294. }]);
  295. done();
  296. });
  297. });
  298. it('should return an error if the response has no statuscode 200', function(done) {
  299. var async = OC.SetupChecks.checkSetup();
  300. suite.server.requests[0].respond(
  301. 500,
  302. {
  303. 'Content-Type': 'application/json'
  304. },
  305. JSON.stringify({data: {serverHasInternetConnectionProblems: true}})
  306. );
  307. async.done(function( data, s, x ){
  308. expect(data).toEqual([{
  309. msg: 'Error occurred while checking server setup',
  310. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  311. }]);
  312. done();
  313. });
  314. });
  315. it('should return an error if the php version is no longer supported', function(done) {
  316. var async = OC.SetupChecks.checkSetup();
  317. suite.server.requests[0].respond(
  318. 200,
  319. {
  320. 'Content-Type': 'application/json',
  321. },
  322. JSON.stringify({
  323. reverseProxyGeneratedURL: 'https://server',
  324. generic: {
  325. network: {
  326. "Internet connectivity": {
  327. severity: "success",
  328. description: null,
  329. linkToDoc: null
  330. }
  331. },
  332. security: {
  333. "Checking for PHP version": {
  334. severity: "warning",
  335. description: "You are currently running PHP 8.0.30. PHP 8.0 is now deprecated in Nextcloud 27. Nextcloud 28 may require at least PHP 8.1. Please upgrade to one of the officially supported PHP versions provided by the PHP Group as soon as possible.",
  336. linkToDoc: "https://secure.php.net/supported-versions.php"
  337. }
  338. },
  339. },
  340. })
  341. );
  342. async.done(function( data, s, x ){
  343. expect(data).toEqual([{
  344. msg: 'You are currently running PHP 8.0.30. PHP 8.0 is now deprecated in Nextcloud 27. Nextcloud 28 may require at least PHP 8.1. Please upgrade to one of the officially supported PHP versions provided by the PHP Group as soon as possible. For more details see the <a target="_blank" rel="noreferrer noopener" class="external" href="https://secure.php.net/supported-versions.php">documentation ↗</a>.',
  345. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  346. }]);
  347. done();
  348. });
  349. });
  350. // THe following test is invalid as the code in core/js/setupchecks.js is calling
  351. // window.location.protocol which always return http during tests
  352. // if there is a way to trick window.location.protocol during test, then we could re-activate it
  353. /*
  354. it('should return an error if the protocol is https but the server generates http links', function(done) {
  355. var async = OC.SetupChecks.checkSetup();
  356. suite.server.requests[0].respond(
  357. 200,
  358. {
  359. 'Content-Type': 'application/json',
  360. },
  361. JSON.stringify({
  362. reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
  363. reverseProxyGeneratedURL: 'http://server',
  364. generic: {
  365. network: {
  366. "Internet connectivity": {
  367. severity: "success",
  368. description: null,
  369. linkToDoc: null
  370. }
  371. },
  372. },
  373. })
  374. );
  375. async.done(function( data, s, x ){
  376. expect(data).toEqual([{
  377. msg: 'You are accessing your instance over a secure connection, however your instance is generating insecure URLs. This most likely means that you are behind a reverse proxy and the overwrite config variables are not set correctly. Please read <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.nextcloud.com/foo/bar.html">the documentation page about this ↗</a>.',
  378. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  379. }]);
  380. done();
  381. });
  382. });
  383. */
  384. it('should not return an error if the protocol is http and the server generates http links', function(done) {
  385. var async = OC.SetupChecks.checkSetup();
  386. suite.server.requests[0].respond(
  387. 200,
  388. {
  389. 'Content-Type': 'application/json',
  390. },
  391. JSON.stringify({
  392. reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
  393. reverseProxyGeneratedURL: 'http://server',
  394. generic: {
  395. network: {
  396. "Internet connectivity": {
  397. severity: "success",
  398. description: null,
  399. linkToDoc: null
  400. }
  401. },
  402. },
  403. })
  404. );
  405. async.done(function( data, s, x ){
  406. expect(data).toEqual([]);
  407. done();
  408. });
  409. });
  410. it('should return an info if there is no default phone region', function(done) {
  411. var async = OC.SetupChecks.checkSetup();
  412. suite.server.requests[0].respond(
  413. 200,
  414. {
  415. 'Content-Type': 'application/json',
  416. },
  417. JSON.stringify({
  418. reverseProxyGeneratedURL: 'https://server',
  419. generic: {
  420. network: {
  421. "Internet connectivity": {
  422. severity: "success",
  423. description: null,
  424. linkToDoc: null
  425. }
  426. },
  427. config: {
  428. "Checking for default phone region": {
  429. severity: "info",
  430. description: "Your installation has no default phone region set. This is required to validate phone numbers in the profile settings without a country code. To allow numbers without a country code, please add \"default_phone_region\" with the respective ISO 3166-1 code of the region to your config file.",
  431. linkToDoc: "https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements"
  432. },
  433. },
  434. },
  435. })
  436. );
  437. async.done(function( data, s, x ){
  438. expect(data).toEqual([{
  439. msg: 'Your installation has no default phone region set. This is required to validate phone numbers in the profile settings without a country code. To allow numbers without a country code, please add &quot;default_phone_region&quot; with the respective ISO 3166-1 code of the region to your config file. For more details see the <a target="_blank" rel="noreferrer noopener" class="external" href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements">documentation ↗</a>.',
  440. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  441. }]);
  442. done();
  443. });
  444. });
  445. });
  446. describe('checkGeneric', function() {
  447. it('should return an error if the response has no statuscode 200', function(done) {
  448. var async = OC.SetupChecks.checkGeneric();
  449. suite.server.requests[0].respond(
  450. 500,
  451. {
  452. 'Content-Type': 'application/json'
  453. }
  454. );
  455. async.done(function( data, s, x ){
  456. expect(data).toEqual([{
  457. msg: 'Error occurred while checking server setup',
  458. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  459. },{
  460. msg: 'Error occurred while checking server setup',
  461. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  462. }]);
  463. done();
  464. });
  465. });
  466. it('should return all errors if all headers are missing', function(done) {
  467. protocolStub.returns('https');
  468. var async = OC.SetupChecks.checkGeneric();
  469. suite.server.requests[0].respond(
  470. 200,
  471. {
  472. 'Content-Type': 'application/json',
  473. 'Strict-Transport-Security': 'max-age=15768000'
  474. },
  475. '{}'
  476. );
  477. async.done(function( data, s, x ){
  478. expect(data).toEqual([
  479. {
  480. msg: 'The "X-Content-Type-Options" HTTP header is not set to "nosniff". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  481. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  482. }, {
  483. msg: 'The "X-Robots-Tag" HTTP header is not set to "noindex, nofollow". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  484. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  485. }, {
  486. msg: 'The "X-Frame-Options" HTTP header is not set to "SAMEORIGIN". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  487. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  488. }, {
  489. msg: 'The "X-Permitted-Cross-Domain-Policies" HTTP header is not set to "none". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  490. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  491. }, {
  492. msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  493. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  494. }, {
  495. msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.',
  496. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  497. }
  498. ]);
  499. done();
  500. });
  501. });
  502. it('should return only some errors if just some headers are missing', function(done) {
  503. protocolStub.returns('https');
  504. var async = OC.SetupChecks.checkGeneric();
  505. suite.server.requests[0].respond(
  506. 200,
  507. {
  508. 'X-Robots-Tag': 'noindex, nofollow',
  509. 'X-Frame-Options': 'SAMEORIGIN',
  510. 'Strict-Transport-Security': 'max-age=15768000;preload',
  511. 'X-Permitted-Cross-Domain-Policies': 'none',
  512. 'Referrer-Policy': 'no-referrer',
  513. }
  514. );
  515. async.done(function( data, s, x ){
  516. expect(data).toEqual([
  517. {
  518. msg: 'The "X-Content-Type-Options" HTTP header is not set to "nosniff". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  519. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  520. }, {
  521. msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  522. type: OC.SetupChecks.MESSAGE_TYPE_WARNING,
  523. }
  524. ]);
  525. done();
  526. });
  527. });
  528. it('should return none errors if all headers are there', function(done) {
  529. protocolStub.returns('https');
  530. var async = OC.SetupChecks.checkGeneric();
  531. suite.server.requests[0].respond(
  532. 200,
  533. {
  534. 'X-XSS-Protection': '1; mode=block',
  535. 'X-Content-Type-Options': 'nosniff',
  536. 'X-Robots-Tag': 'noindex, nofollow',
  537. 'X-Frame-Options': 'SAMEORIGIN',
  538. 'Strict-Transport-Security': 'max-age=15768000',
  539. 'X-Permitted-Cross-Domain-Policies': 'none',
  540. 'Referrer-Policy': 'no-referrer'
  541. }
  542. );
  543. async.done(function( data, s, x ){
  544. expect(data).toEqual([]);
  545. done();
  546. });
  547. });
  548. describe('check X-Robots-Tag header', function() {
  549. it('should return no message if X-Robots-Tag is set to noindex,nofollow without space', function(done) {
  550. protocolStub.returns('https');
  551. var result = OC.SetupChecks.checkGeneric();
  552. suite.server.requests[0].respond(200, {
  553. 'Strict-Transport-Security': 'max-age=15768000',
  554. 'X-XSS-Protection': '1; mode=block',
  555. 'X-Content-Type-Options': 'nosniff',
  556. 'X-Robots-Tag': 'noindex,nofollow',
  557. 'X-Frame-Options': 'SAMEORIGIN',
  558. 'X-Permitted-Cross-Domain-Policies': 'none',
  559. 'Referrer-Policy': 'no-referrer',
  560. });
  561. result.done(function( data, s, x ){
  562. expect(data).toEqual([]);
  563. done();
  564. });
  565. });
  566. it('should return a message if X-Robots-Tag is set to none', function(done) {
  567. protocolStub.returns('https');
  568. var result = OC.SetupChecks.checkGeneric();
  569. suite.server.requests[0].respond(200, {
  570. 'Strict-Transport-Security': 'max-age=15768000',
  571. 'X-XSS-Protection': '1; mode=block',
  572. 'X-Content-Type-Options': 'nosniff',
  573. 'X-Robots-Tag': 'none',
  574. 'X-Frame-Options': 'SAMEORIGIN',
  575. 'X-Permitted-Cross-Domain-Policies': 'none',
  576. 'Referrer-Policy': 'no-referrer',
  577. });
  578. result.done(function( data, s, x ){
  579. expect(data).toEqual([
  580. {
  581. msg: 'The "X-Robots-Tag" HTTP header is not set to "noindex, nofollow". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  582. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  583. }
  584. ]);
  585. done();
  586. });
  587. });
  588. });
  589. describe('check X-XSS-Protection header', function() {
  590. it('should return no message if X-XSS-Protection is set to 1; mode=block; report=https://example.com', function(done) {
  591. protocolStub.returns('https');
  592. var result = OC.SetupChecks.checkGeneric();
  593. suite.server.requests[0].respond(200, {
  594. 'Strict-Transport-Security': 'max-age=15768000',
  595. 'X-XSS-Protection': '1; mode=block; report=https://example.com',
  596. 'X-Content-Type-Options': 'nosniff',
  597. 'X-Robots-Tag': 'noindex, nofollow',
  598. 'X-Frame-Options': 'SAMEORIGIN',
  599. 'X-Permitted-Cross-Domain-Policies': 'none',
  600. 'Referrer-Policy': 'no-referrer',
  601. });
  602. result.done(function( data, s, x ){
  603. expect(data).toEqual([]);
  604. done();
  605. });
  606. });
  607. it('should return no message if X-XSS-Protection is set to 1; mode=block', function(done) {
  608. protocolStub.returns('https');
  609. var result = OC.SetupChecks.checkGeneric();
  610. suite.server.requests[0].respond(200, {
  611. 'Strict-Transport-Security': 'max-age=15768000',
  612. 'X-XSS-Protection': '1; mode=block',
  613. 'X-Content-Type-Options': 'nosniff',
  614. 'X-Robots-Tag': 'noindex, nofollow',
  615. 'X-Frame-Options': 'SAMEORIGIN',
  616. 'X-Permitted-Cross-Domain-Policies': 'none',
  617. 'Referrer-Policy': 'no-referrer',
  618. });
  619. result.done(function( data, s, x ){
  620. expect(data).toEqual([]);
  621. done();
  622. });
  623. });
  624. it('should return a message if X-XSS-Protection is set to 1', function(done) {
  625. protocolStub.returns('https');
  626. var result = OC.SetupChecks.checkGeneric();
  627. suite.server.requests[0].respond(200, {
  628. 'Strict-Transport-Security': 'max-age=15768000',
  629. 'X-XSS-Protection': '1',
  630. 'X-Content-Type-Options': 'nosniff',
  631. 'X-Robots-Tag': 'noindex, nofollow',
  632. 'X-Frame-Options': 'SAMEORIGIN',
  633. 'X-Permitted-Cross-Domain-Policies': 'none',
  634. 'Referrer-Policy': 'no-referrer',
  635. });
  636. result.done(function( data, s, x ){
  637. expect(data).toEqual([
  638. {
  639. msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  640. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  641. }
  642. ]);
  643. done();
  644. });
  645. });
  646. it('should return a message if X-XSS-Protection is set to 0', function(done) {
  647. protocolStub.returns('https');
  648. var result = OC.SetupChecks.checkGeneric();
  649. suite.server.requests[0].respond(200, {
  650. 'Strict-Transport-Security': 'max-age=15768000',
  651. 'X-XSS-Protection': '0',
  652. 'X-Content-Type-Options': 'nosniff',
  653. 'X-Robots-Tag': 'noindex, nofollow',
  654. 'X-Frame-Options': 'SAMEORIGIN',
  655. 'X-Permitted-Cross-Domain-Policies': 'none',
  656. 'Referrer-Policy': 'no-referrer',
  657. });
  658. result.done(function( data, s, x ){
  659. expect(data).toEqual([
  660. {
  661. msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.',
  662. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  663. }
  664. ]);
  665. done();
  666. });
  667. });
  668. });
  669. describe('check Referrer-Policy header', function() {
  670. it('should return no message if Referrer-Policy is set to no-referrer', function(done) {
  671. protocolStub.returns('https');
  672. var result = OC.SetupChecks.checkGeneric();
  673. suite.server.requests[0].respond(200, {
  674. 'Strict-Transport-Security': 'max-age=15768000',
  675. 'X-XSS-Protection': '1; mode=block',
  676. 'X-Content-Type-Options': 'nosniff',
  677. 'X-Robots-Tag': 'noindex, nofollow',
  678. 'X-Frame-Options': 'SAMEORIGIN',
  679. 'X-Permitted-Cross-Domain-Policies': 'none',
  680. 'Referrer-Policy': 'no-referrer',
  681. });
  682. result.done(function( data, s, x ){
  683. expect(data).toEqual([]);
  684. done();
  685. });
  686. });
  687. it('should return no message if Referrer-Policy is set to no-referrer-when-downgrade', function(done) {
  688. protocolStub.returns('https');
  689. var result = OC.SetupChecks.checkGeneric();
  690. suite.server.requests[0].respond(200, {
  691. 'Strict-Transport-Security': 'max-age=15768000',
  692. 'X-XSS-Protection': '1; mode=block',
  693. 'X-Content-Type-Options': 'nosniff',
  694. 'X-Robots-Tag': 'noindex, nofollow',
  695. 'X-Frame-Options': 'SAMEORIGIN',
  696. 'X-Permitted-Cross-Domain-Policies': 'none',
  697. 'Referrer-Policy': 'no-referrer-when-downgrade',
  698. });
  699. result.done(function( data, s, x ){
  700. expect(data).toEqual([]);
  701. done();
  702. });
  703. });
  704. it('should return no message if Referrer-Policy is set to strict-origin', function(done) {
  705. protocolStub.returns('https');
  706. var result = OC.SetupChecks.checkGeneric();
  707. suite.server.requests[0].respond(200, {
  708. 'Strict-Transport-Security': 'max-age=15768000',
  709. 'X-XSS-Protection': '1; mode=block',
  710. 'X-Content-Type-Options': 'nosniff',
  711. 'X-Robots-Tag': 'noindex, nofollow',
  712. 'X-Frame-Options': 'SAMEORIGIN',
  713. 'X-Permitted-Cross-Domain-Policies': 'none',
  714. 'Referrer-Policy': 'strict-origin',
  715. });
  716. result.done(function( data, s, x ){
  717. expect(data).toEqual([]);
  718. done();
  719. });
  720. });
  721. it('should return no message if Referrer-Policy is set to strict-origin-when-cross-origin', function(done) {
  722. protocolStub.returns('https');
  723. var result = OC.SetupChecks.checkGeneric();
  724. suite.server.requests[0].respond(200, {
  725. 'Strict-Transport-Security': 'max-age=15768000',
  726. 'X-XSS-Protection': '1; mode=block',
  727. 'X-Content-Type-Options': 'nosniff',
  728. 'X-Robots-Tag': 'noindex, nofollow',
  729. 'X-Frame-Options': 'SAMEORIGIN',
  730. 'X-Permitted-Cross-Domain-Policies': 'none',
  731. 'Referrer-Policy': 'strict-origin-when-cross-origin',
  732. });
  733. result.done(function( data, s, x ){
  734. expect(data).toEqual([]);
  735. done();
  736. });
  737. });
  738. it('should return no message if Referrer-Policy is set to same-origin', function(done) {
  739. protocolStub.returns('https');
  740. var result = OC.SetupChecks.checkGeneric();
  741. suite.server.requests[0].respond(200, {
  742. 'Strict-Transport-Security': 'max-age=15768000',
  743. 'X-XSS-Protection': '1; mode=block',
  744. 'X-Content-Type-Options': 'nosniff',
  745. 'X-Robots-Tag': 'noindex, nofollow',
  746. 'X-Frame-Options': 'SAMEORIGIN',
  747. 'X-Permitted-Cross-Domain-Policies': 'none',
  748. 'Referrer-Policy': 'same-origin',
  749. });
  750. result.done(function( data, s, x ){
  751. expect(data).toEqual([]);
  752. done();
  753. });
  754. });
  755. it('should return a message if Referrer-Policy is set to origin', function(done) {
  756. protocolStub.returns('https');
  757. var result = OC.SetupChecks.checkGeneric();
  758. suite.server.requests[0].respond(200, {
  759. 'Strict-Transport-Security': 'max-age=15768000',
  760. 'X-XSS-Protection': '1; mode=block',
  761. 'X-Content-Type-Options': 'nosniff',
  762. 'X-Robots-Tag': 'noindex, nofollow',
  763. 'X-Frame-Options': 'SAMEORIGIN',
  764. 'X-Permitted-Cross-Domain-Policies': 'none',
  765. 'Referrer-Policy': 'origin',
  766. });
  767. result.done(function( data, s, x ){
  768. expect(data).toEqual([
  769. {
  770. msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.',
  771. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  772. }
  773. ]);
  774. done();
  775. });
  776. });
  777. it('should return a message if Referrer-Policy is set to origin-when-cross-origin', function(done) {
  778. protocolStub.returns('https');
  779. var result = OC.SetupChecks.checkGeneric();
  780. suite.server.requests[0].respond(200, {
  781. 'Strict-Transport-Security': 'max-age=15768000',
  782. 'X-XSS-Protection': '1; mode=block',
  783. 'X-Content-Type-Options': 'nosniff',
  784. 'X-Robots-Tag': 'noindex, nofollow',
  785. 'X-Frame-Options': 'SAMEORIGIN',
  786. 'X-Permitted-Cross-Domain-Policies': 'none',
  787. 'Referrer-Policy': 'origin-when-cross-origin',
  788. });
  789. result.done(function( data, s, x ){
  790. expect(data).toEqual([
  791. {
  792. msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.',
  793. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  794. }
  795. ]);
  796. done();
  797. });
  798. });
  799. it('should return a message if Referrer-Policy is set to unsafe-url', function(done) {
  800. protocolStub.returns('https');
  801. var result = OC.SetupChecks.checkGeneric();
  802. suite.server.requests[0].respond(200, {
  803. 'Strict-Transport-Security': 'max-age=15768000',
  804. 'X-XSS-Protection': '1; mode=block',
  805. 'X-Content-Type-Options': 'nosniff',
  806. 'X-Robots-Tag': 'noindex, nofollow',
  807. 'X-Frame-Options': 'SAMEORIGIN',
  808. 'X-Permitted-Cross-Domain-Policies': 'none',
  809. 'Referrer-Policy': 'unsafe-url',
  810. });
  811. result.done(function( data, s, x ){
  812. expect(data).toEqual([
  813. {
  814. msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.',
  815. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  816. }
  817. ]);
  818. done();
  819. });
  820. });
  821. });
  822. });
  823. it('should return an error if the response has no statuscode 200', function(done) {
  824. var async = OC.SetupChecks.checkGeneric();
  825. suite.server.requests[0].respond(
  826. 500,
  827. {
  828. 'Content-Type': 'application/json'
  829. },
  830. JSON.stringify({data: {serverHasInternetConnectionProblems: true}})
  831. );
  832. async.done(function( data, s, x ){
  833. expect(data).toEqual([{
  834. msg: 'Error occurred while checking server setup',
  835. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  836. }, {
  837. msg: 'Error occurred while checking server setup',
  838. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  839. }]);
  840. done();
  841. });
  842. });
  843. it('should return a SSL warning if SSL used without Strict-Transport-Security-Header', function(done) {
  844. protocolStub.returns('https');
  845. var async = OC.SetupChecks.checkGeneric();
  846. suite.server.requests[0].respond(200,
  847. {
  848. 'X-XSS-Protection': '1; mode=block',
  849. 'X-Content-Type-Options': 'nosniff',
  850. 'X-Robots-Tag': 'noindex, nofollow',
  851. 'X-Frame-Options': 'SAMEORIGIN',
  852. 'X-Permitted-Cross-Domain-Policies': 'none',
  853. 'Referrer-Policy': 'no-referrer',
  854. }
  855. );
  856. async.done(function( data, s, x ){
  857. expect(data).toEqual([{
  858. msg: 'The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-security">security tips ↗</a>.',
  859. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  860. }]);
  861. done();
  862. });
  863. });
  864. it('should return a SSL warning if SSL used with to small Strict-Transport-Security-Header', function(done) {
  865. protocolStub.returns('https');
  866. var async = OC.SetupChecks.checkGeneric();
  867. suite.server.requests[0].respond(200,
  868. {
  869. 'Strict-Transport-Security': 'max-age=15551999',
  870. 'X-XSS-Protection': '1; mode=block',
  871. 'X-Content-Type-Options': 'nosniff',
  872. 'X-Robots-Tag': 'noindex, nofollow',
  873. 'X-Frame-Options': 'SAMEORIGIN',
  874. 'X-Permitted-Cross-Domain-Policies': 'none',
  875. 'Referrer-Policy': 'no-referrer',
  876. }
  877. );
  878. async.done(function( data, s, x ){
  879. expect(data).toEqual([{
  880. msg: 'The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-security">security tips ↗</a>.',
  881. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  882. }]);
  883. done();
  884. });
  885. });
  886. it('should return a SSL warning if SSL used with to a bogus Strict-Transport-Security-Header', function(done) {
  887. protocolStub.returns('https');
  888. var async = OC.SetupChecks.checkGeneric();
  889. suite.server.requests[0].respond(200,
  890. {
  891. 'Strict-Transport-Security': 'iAmABogusHeader342',
  892. 'X-XSS-Protection': '1; mode=block',
  893. 'X-Content-Type-Options': 'nosniff',
  894. 'X-Robots-Tag': 'noindex, nofollow',
  895. 'X-Frame-Options': 'SAMEORIGIN',
  896. 'X-Permitted-Cross-Domain-Policies': 'none',
  897. 'Referrer-Policy': 'no-referrer',
  898. }
  899. );
  900. async.done(function( data, s, x ){
  901. expect(data).toEqual([{
  902. msg: 'The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-security">security tips ↗</a>.',
  903. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  904. }]);
  905. done();
  906. });
  907. });
  908. it('should return no SSL warning if SSL used with to exact the minimum Strict-Transport-Security-Header', function(done) {
  909. protocolStub.returns('https');
  910. var async = OC.SetupChecks.checkGeneric();
  911. suite.server.requests[0].respond(200, {
  912. 'Strict-Transport-Security': 'max-age=15768000',
  913. 'X-XSS-Protection': '1; mode=block',
  914. 'X-Content-Type-Options': 'nosniff',
  915. 'X-Robots-Tag': 'noindex, nofollow',
  916. 'X-Frame-Options': 'SAMEORIGIN',
  917. 'X-Permitted-Cross-Domain-Policies': 'none',
  918. 'Referrer-Policy': 'no-referrer',
  919. });
  920. async.done(function( data, s, x ){
  921. expect(data).toEqual([]);
  922. done();
  923. });
  924. });
  925. it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header', function(done) {
  926. protocolStub.returns('https');
  927. var async = OC.SetupChecks.checkGeneric();
  928. suite.server.requests[0].respond(200, {
  929. 'Strict-Transport-Security': 'max-age=99999999',
  930. 'X-XSS-Protection': '1; mode=block',
  931. 'X-Content-Type-Options': 'nosniff',
  932. 'X-Robots-Tag': 'noindex, nofollow',
  933. 'X-Frame-Options': 'SAMEORIGIN',
  934. 'X-Permitted-Cross-Domain-Policies': 'none',
  935. 'Referrer-Policy': 'no-referrer',
  936. });
  937. async.done(function( data, s, x ){
  938. expect(data).toEqual([]);
  939. done();
  940. });
  941. });
  942. it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header and includeSubDomains parameter', function(done) {
  943. protocolStub.returns('https');
  944. var async = OC.SetupChecks.checkGeneric();
  945. suite.server.requests[0].respond(200, {
  946. 'Strict-Transport-Security': 'max-age=99999999; includeSubDomains',
  947. 'X-XSS-Protection': '1; mode=block',
  948. 'X-Content-Type-Options': 'nosniff',
  949. 'X-Robots-Tag': 'noindex, nofollow',
  950. 'X-Frame-Options': 'SAMEORIGIN',
  951. 'X-Permitted-Cross-Domain-Policies': 'none',
  952. 'Referrer-Policy': 'no-referrer',
  953. });
  954. async.done(function( data, s, x ){
  955. expect(data).toEqual([]);
  956. done();
  957. });
  958. });
  959. it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header and includeSubDomains and preload parameter', function(done) {
  960. protocolStub.returns('https');
  961. var async = OC.SetupChecks.checkGeneric();
  962. suite.server.requests[0].respond(200, {
  963. 'Strict-Transport-Security': 'max-age=99999999; preload; includeSubDomains',
  964. 'X-XSS-Protection': '1; mode=block',
  965. 'X-Content-Type-Options': 'nosniff',
  966. 'X-Robots-Tag': 'noindex, nofollow',
  967. 'X-Frame-Options': 'SAMEORIGIN',
  968. 'X-Permitted-Cross-Domain-Policies': 'none',
  969. 'Referrer-Policy': 'no-referrer',
  970. });
  971. async.done(function( data, s, x ){
  972. expect(data).toEqual([]);
  973. done();
  974. });
  975. });
  976. });