setupchecksSpec.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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('checkDataProtected', function() {
  115. oc_dataURL = "data";
  116. it('should return an error if data directory is not protected', function(done) {
  117. var async = OC.SetupChecks.checkDataProtected();
  118. suite.server.requests[0].respond(200, {'Content-Type': 'text/plain'}, '');
  119. async.done(function( data, s, x ){
  120. expect(data).toEqual([
  121. {
  122. 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.',
  123. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  124. }]);
  125. done();
  126. });
  127. });
  128. it('should not return an error if data directory is protected', function(done) {
  129. var async = OC.SetupChecks.checkDataProtected();
  130. suite.server.requests[0].respond(403);
  131. async.done(function( data, s, x ){
  132. expect(data).toEqual([]);
  133. done();
  134. });
  135. });
  136. it('should return an error if data directory is a boolean', function(done) {
  137. oc_dataURL = false;
  138. var async = OC.SetupChecks.checkDataProtected();
  139. async.done(function( data, s, x ){
  140. expect(data).toEqual([]);
  141. done();
  142. });
  143. });
  144. });
  145. describe('checkSetup', function() {
  146. it('should return an error if server has no internet connection', function(done) {
  147. var async = OC.SetupChecks.checkSetup();
  148. suite.server.requests[0].respond(
  149. 200,
  150. {
  151. 'Content-Type': 'application/json'
  152. },
  153. JSON.stringify({
  154. reverseProxyGeneratedURL: 'https://server',
  155. generic: {
  156. network: {
  157. "Internet connectivity": {
  158. severity: "warning",
  159. 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.',
  160. linkToDoc: null
  161. }
  162. },
  163. },
  164. })
  165. );
  166. async.done(function( data, s, x ){
  167. expect(data).toEqual([
  168. {
  169. 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.',
  170. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  171. },
  172. ]);
  173. done();
  174. });
  175. });
  176. it('should return an error if server has no internet connection and data directory is not protected', function(done) {
  177. var async = OC.SetupChecks.checkSetup();
  178. suite.server.requests[0].respond(
  179. 200,
  180. {
  181. 'Content-Type': 'application/json'
  182. },
  183. JSON.stringify({
  184. reverseProxyGeneratedURL: 'https://server',
  185. generic: {
  186. network: {
  187. "Internet connectivity": {
  188. severity: "warning",
  189. 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.',
  190. linkToDoc: null
  191. }
  192. },
  193. },
  194. })
  195. );
  196. async.done(function( data, s, x ){
  197. expect(data).toEqual([
  198. {
  199. 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.',
  200. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  201. },
  202. ]);
  203. done();
  204. });
  205. });
  206. it('should return an error if server has no internet connection and data directory is not protected and memcache is available', function(done) {
  207. var async = OC.SetupChecks.checkSetup();
  208. suite.server.requests[0].respond(
  209. 200,
  210. {
  211. 'Content-Type': 'application/json',
  212. },
  213. JSON.stringify({
  214. reverseProxyGeneratedURL: 'https://server',
  215. generic: {
  216. network: {
  217. "Internet connectivity": {
  218. severity: "warning",
  219. 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.',
  220. linkToDoc: null
  221. }
  222. },
  223. },
  224. })
  225. );
  226. async.done(function( data, s, x ){
  227. expect(data).toEqual([
  228. {
  229. 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.',
  230. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  231. }
  232. ]);
  233. done();
  234. });
  235. });
  236. it('should return a warning if the memory limit is below the recommended value', function(done) {
  237. var async = OC.SetupChecks.checkSetup();
  238. suite.server.requests[0].respond(
  239. 200,
  240. {
  241. 'Content-Type': 'application/json',
  242. },
  243. JSON.stringify({
  244. reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
  245. reverseProxyGeneratedURL: 'https://server',
  246. generic: {
  247. network: {
  248. "Internet connectivity": {
  249. severity: "success",
  250. description: null,
  251. linkToDoc: null
  252. }
  253. },
  254. php: {
  255. "Internet connectivity": {
  256. severity: "success",
  257. description: null,
  258. linkToDoc: null
  259. },
  260. "PHP memory limit": {
  261. severity: "error",
  262. description: "The PHP memory limit is below the recommended value of 512MB.",
  263. linkToDoc: null
  264. },
  265. },
  266. },
  267. })
  268. );
  269. async.done(function( data, s, x ){
  270. expect(data).toEqual([{
  271. msg: 'The PHP memory limit is below the recommended value of 512MB.',
  272. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  273. }]);
  274. done();
  275. });
  276. });
  277. it('should return an error if the response has no statuscode 200', function(done) {
  278. var async = OC.SetupChecks.checkSetup();
  279. suite.server.requests[0].respond(
  280. 500,
  281. {
  282. 'Content-Type': 'application/json'
  283. },
  284. JSON.stringify({data: {serverHasInternetConnectionProblems: true}})
  285. );
  286. async.done(function( data, s, x ){
  287. expect(data).toEqual([{
  288. msg: 'Error occurred while checking server setup',
  289. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  290. }]);
  291. done();
  292. });
  293. });
  294. it('should return an error if the php version is no longer supported', function(done) {
  295. var async = OC.SetupChecks.checkSetup();
  296. suite.server.requests[0].respond(
  297. 200,
  298. {
  299. 'Content-Type': 'application/json',
  300. },
  301. JSON.stringify({
  302. reverseProxyGeneratedURL: 'https://server',
  303. generic: {
  304. network: {
  305. "Internet connectivity": {
  306. severity: "success",
  307. description: null,
  308. linkToDoc: null
  309. }
  310. },
  311. security: {
  312. "Checking for PHP version": {
  313. severity: "warning",
  314. 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.",
  315. linkToDoc: "https://secure.php.net/supported-versions.php"
  316. }
  317. },
  318. },
  319. })
  320. );
  321. async.done(function( data, s, x ){
  322. expect(data).toEqual([{
  323. 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>.',
  324. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  325. }]);
  326. done();
  327. });
  328. });
  329. // THe following test is invalid as the code in core/js/setupchecks.js is calling
  330. // window.location.protocol which always return http during tests
  331. // if there is a way to trick window.location.protocol during test, then we could re-activate it
  332. /*
  333. it('should return an error if the protocol is https but the server generates http links', function(done) {
  334. var async = OC.SetupChecks.checkSetup();
  335. suite.server.requests[0].respond(
  336. 200,
  337. {
  338. 'Content-Type': 'application/json',
  339. },
  340. JSON.stringify({
  341. reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
  342. reverseProxyGeneratedURL: 'http://server',
  343. generic: {
  344. network: {
  345. "Internet connectivity": {
  346. severity: "success",
  347. description: null,
  348. linkToDoc: null
  349. }
  350. },
  351. },
  352. })
  353. );
  354. async.done(function( data, s, x ){
  355. expect(data).toEqual([{
  356. 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>.',
  357. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  358. }]);
  359. done();
  360. });
  361. });
  362. */
  363. it('should not return an error if the protocol is http and the server generates http links', function(done) {
  364. var async = OC.SetupChecks.checkSetup();
  365. suite.server.requests[0].respond(
  366. 200,
  367. {
  368. 'Content-Type': 'application/json',
  369. },
  370. JSON.stringify({
  371. reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
  372. reverseProxyGeneratedURL: 'http://server',
  373. generic: {
  374. network: {
  375. "Internet connectivity": {
  376. severity: "success",
  377. description: null,
  378. linkToDoc: null
  379. }
  380. },
  381. },
  382. })
  383. );
  384. async.done(function( data, s, x ){
  385. expect(data).toEqual([]);
  386. done();
  387. });
  388. });
  389. it('should return an info if there is no default phone region', function(done) {
  390. var async = OC.SetupChecks.checkSetup();
  391. suite.server.requests[0].respond(
  392. 200,
  393. {
  394. 'Content-Type': 'application/json',
  395. },
  396. JSON.stringify({
  397. reverseProxyGeneratedURL: 'https://server',
  398. generic: {
  399. network: {
  400. "Internet connectivity": {
  401. severity: "success",
  402. description: null,
  403. linkToDoc: null
  404. }
  405. },
  406. config: {
  407. "Checking for default phone region": {
  408. severity: "info",
  409. 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.",
  410. linkToDoc: "https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements"
  411. },
  412. },
  413. },
  414. })
  415. );
  416. async.done(function( data, s, x ){
  417. expect(data).toEqual([{
  418. 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>.',
  419. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  420. }]);
  421. done();
  422. });
  423. });
  424. });
  425. describe('checkGeneric', function() {
  426. it('should return an error if the response has no statuscode 200', function(done) {
  427. var async = OC.SetupChecks.checkGeneric();
  428. suite.server.requests[0].respond(
  429. 500,
  430. {
  431. 'Content-Type': 'application/json'
  432. }
  433. );
  434. async.done(function( data, s, x ){
  435. expect(data).toEqual([{
  436. msg: 'Error occurred while checking server setup',
  437. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  438. },{
  439. msg: 'Error occurred while checking server setup',
  440. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  441. }]);
  442. done();
  443. });
  444. });
  445. it('should return all errors if all headers are missing', function(done) {
  446. protocolStub.returns('https');
  447. var async = OC.SetupChecks.checkGeneric();
  448. suite.server.requests[0].respond(
  449. 200,
  450. {
  451. 'Content-Type': 'application/json',
  452. 'Strict-Transport-Security': 'max-age=15768000'
  453. },
  454. '{}'
  455. );
  456. async.done(function( data, s, x ){
  457. expect(data).toEqual([
  458. {
  459. 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.',
  460. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  461. }, {
  462. 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.',
  463. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  464. }, {
  465. 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.',
  466. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  467. }, {
  468. 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.',
  469. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  470. }, {
  471. 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.',
  472. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  473. }, {
  474. 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>.',
  475. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  476. }
  477. ]);
  478. done();
  479. });
  480. });
  481. it('should return only some errors if just some headers are missing', function(done) {
  482. protocolStub.returns('https');
  483. var async = OC.SetupChecks.checkGeneric();
  484. suite.server.requests[0].respond(
  485. 200,
  486. {
  487. 'X-Robots-Tag': 'noindex, nofollow',
  488. 'X-Frame-Options': 'SAMEORIGIN',
  489. 'Strict-Transport-Security': 'max-age=15768000;preload',
  490. 'X-Permitted-Cross-Domain-Policies': 'none',
  491. 'Referrer-Policy': 'no-referrer',
  492. }
  493. );
  494. async.done(function( data, s, x ){
  495. expect(data).toEqual([
  496. {
  497. 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.',
  498. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  499. }, {
  500. 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.',
  501. type: OC.SetupChecks.MESSAGE_TYPE_WARNING,
  502. }
  503. ]);
  504. done();
  505. });
  506. });
  507. it('should return none errors if all headers are there', function(done) {
  508. protocolStub.returns('https');
  509. var async = OC.SetupChecks.checkGeneric();
  510. suite.server.requests[0].respond(
  511. 200,
  512. {
  513. 'X-XSS-Protection': '1; mode=block',
  514. 'X-Content-Type-Options': 'nosniff',
  515. 'X-Robots-Tag': 'noindex, nofollow',
  516. 'X-Frame-Options': 'SAMEORIGIN',
  517. 'Strict-Transport-Security': 'max-age=15768000',
  518. 'X-Permitted-Cross-Domain-Policies': 'none',
  519. 'Referrer-Policy': 'no-referrer'
  520. }
  521. );
  522. async.done(function( data, s, x ){
  523. expect(data).toEqual([]);
  524. done();
  525. });
  526. });
  527. describe('check X-Robots-Tag header', function() {
  528. it('should return no message if X-Robots-Tag is set to noindex,nofollow without space', function(done) {
  529. protocolStub.returns('https');
  530. var result = OC.SetupChecks.checkGeneric();
  531. suite.server.requests[0].respond(200, {
  532. 'Strict-Transport-Security': 'max-age=15768000',
  533. 'X-XSS-Protection': '1; mode=block',
  534. 'X-Content-Type-Options': 'nosniff',
  535. 'X-Robots-Tag': 'noindex,nofollow',
  536. 'X-Frame-Options': 'SAMEORIGIN',
  537. 'X-Permitted-Cross-Domain-Policies': 'none',
  538. 'Referrer-Policy': 'no-referrer',
  539. });
  540. result.done(function( data, s, x ){
  541. expect(data).toEqual([]);
  542. done();
  543. });
  544. });
  545. it('should return a message if X-Robots-Tag is set to none', function(done) {
  546. protocolStub.returns('https');
  547. var result = OC.SetupChecks.checkGeneric();
  548. suite.server.requests[0].respond(200, {
  549. 'Strict-Transport-Security': 'max-age=15768000',
  550. 'X-XSS-Protection': '1; mode=block',
  551. 'X-Content-Type-Options': 'nosniff',
  552. 'X-Robots-Tag': 'none',
  553. 'X-Frame-Options': 'SAMEORIGIN',
  554. 'X-Permitted-Cross-Domain-Policies': 'none',
  555. 'Referrer-Policy': 'no-referrer',
  556. });
  557. result.done(function( data, s, x ){
  558. expect(data).toEqual([
  559. {
  560. 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.',
  561. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  562. }
  563. ]);
  564. done();
  565. });
  566. });
  567. });
  568. describe('check X-XSS-Protection header', function() {
  569. it('should return no message if X-XSS-Protection is set to 1; mode=block; report=https://example.com', function(done) {
  570. protocolStub.returns('https');
  571. var result = OC.SetupChecks.checkGeneric();
  572. suite.server.requests[0].respond(200, {
  573. 'Strict-Transport-Security': 'max-age=15768000',
  574. 'X-XSS-Protection': '1; mode=block; report=https://example.com',
  575. 'X-Content-Type-Options': 'nosniff',
  576. 'X-Robots-Tag': 'noindex, nofollow',
  577. 'X-Frame-Options': 'SAMEORIGIN',
  578. 'X-Permitted-Cross-Domain-Policies': 'none',
  579. 'Referrer-Policy': 'no-referrer',
  580. });
  581. result.done(function( data, s, x ){
  582. expect(data).toEqual([]);
  583. done();
  584. });
  585. });
  586. it('should return no message if X-XSS-Protection is set to 1; mode=block', function(done) {
  587. protocolStub.returns('https');
  588. var result = OC.SetupChecks.checkGeneric();
  589. suite.server.requests[0].respond(200, {
  590. 'Strict-Transport-Security': 'max-age=15768000',
  591. 'X-XSS-Protection': '1; mode=block',
  592. 'X-Content-Type-Options': 'nosniff',
  593. 'X-Robots-Tag': 'noindex, nofollow',
  594. 'X-Frame-Options': 'SAMEORIGIN',
  595. 'X-Permitted-Cross-Domain-Policies': 'none',
  596. 'Referrer-Policy': 'no-referrer',
  597. });
  598. result.done(function( data, s, x ){
  599. expect(data).toEqual([]);
  600. done();
  601. });
  602. });
  603. it('should return a message if X-XSS-Protection is set to 1', function(done) {
  604. protocolStub.returns('https');
  605. var result = OC.SetupChecks.checkGeneric();
  606. suite.server.requests[0].respond(200, {
  607. 'Strict-Transport-Security': 'max-age=15768000',
  608. 'X-XSS-Protection': '1',
  609. 'X-Content-Type-Options': 'nosniff',
  610. 'X-Robots-Tag': 'noindex, nofollow',
  611. 'X-Frame-Options': 'SAMEORIGIN',
  612. 'X-Permitted-Cross-Domain-Policies': 'none',
  613. 'Referrer-Policy': 'no-referrer',
  614. });
  615. result.done(function( data, s, x ){
  616. expect(data).toEqual([
  617. {
  618. 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.',
  619. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  620. }
  621. ]);
  622. done();
  623. });
  624. });
  625. it('should return a message if X-XSS-Protection is set to 0', function(done) {
  626. protocolStub.returns('https');
  627. var result = OC.SetupChecks.checkGeneric();
  628. suite.server.requests[0].respond(200, {
  629. 'Strict-Transport-Security': 'max-age=15768000',
  630. 'X-XSS-Protection': '0',
  631. 'X-Content-Type-Options': 'nosniff',
  632. 'X-Robots-Tag': 'noindex, nofollow',
  633. 'X-Frame-Options': 'SAMEORIGIN',
  634. 'X-Permitted-Cross-Domain-Policies': 'none',
  635. 'Referrer-Policy': 'no-referrer',
  636. });
  637. result.done(function( data, s, x ){
  638. expect(data).toEqual([
  639. {
  640. 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.',
  641. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  642. }
  643. ]);
  644. done();
  645. });
  646. });
  647. });
  648. describe('check Referrer-Policy header', function() {
  649. it('should return no message if Referrer-Policy is set to no-referrer', function(done) {
  650. protocolStub.returns('https');
  651. var result = OC.SetupChecks.checkGeneric();
  652. suite.server.requests[0].respond(200, {
  653. 'Strict-Transport-Security': 'max-age=15768000',
  654. 'X-XSS-Protection': '1; mode=block',
  655. 'X-Content-Type-Options': 'nosniff',
  656. 'X-Robots-Tag': 'noindex, nofollow',
  657. 'X-Frame-Options': 'SAMEORIGIN',
  658. 'X-Permitted-Cross-Domain-Policies': 'none',
  659. 'Referrer-Policy': 'no-referrer',
  660. });
  661. result.done(function( data, s, x ){
  662. expect(data).toEqual([]);
  663. done();
  664. });
  665. });
  666. it('should return no message if Referrer-Policy is set to no-referrer-when-downgrade', function(done) {
  667. protocolStub.returns('https');
  668. var result = OC.SetupChecks.checkGeneric();
  669. suite.server.requests[0].respond(200, {
  670. 'Strict-Transport-Security': 'max-age=15768000',
  671. 'X-XSS-Protection': '1; mode=block',
  672. 'X-Content-Type-Options': 'nosniff',
  673. 'X-Robots-Tag': 'noindex, nofollow',
  674. 'X-Frame-Options': 'SAMEORIGIN',
  675. 'X-Permitted-Cross-Domain-Policies': 'none',
  676. 'Referrer-Policy': 'no-referrer-when-downgrade',
  677. });
  678. result.done(function( data, s, x ){
  679. expect(data).toEqual([]);
  680. done();
  681. });
  682. });
  683. it('should return no message if Referrer-Policy is set to strict-origin', function(done) {
  684. protocolStub.returns('https');
  685. var result = OC.SetupChecks.checkGeneric();
  686. suite.server.requests[0].respond(200, {
  687. 'Strict-Transport-Security': 'max-age=15768000',
  688. 'X-XSS-Protection': '1; mode=block',
  689. 'X-Content-Type-Options': 'nosniff',
  690. 'X-Robots-Tag': 'noindex, nofollow',
  691. 'X-Frame-Options': 'SAMEORIGIN',
  692. 'X-Permitted-Cross-Domain-Policies': 'none',
  693. 'Referrer-Policy': 'strict-origin',
  694. });
  695. result.done(function( data, s, x ){
  696. expect(data).toEqual([]);
  697. done();
  698. });
  699. });
  700. it('should return no message if Referrer-Policy is set to strict-origin-when-cross-origin', function(done) {
  701. protocolStub.returns('https');
  702. var result = OC.SetupChecks.checkGeneric();
  703. suite.server.requests[0].respond(200, {
  704. 'Strict-Transport-Security': 'max-age=15768000',
  705. 'X-XSS-Protection': '1; mode=block',
  706. 'X-Content-Type-Options': 'nosniff',
  707. 'X-Robots-Tag': 'noindex, nofollow',
  708. 'X-Frame-Options': 'SAMEORIGIN',
  709. 'X-Permitted-Cross-Domain-Policies': 'none',
  710. 'Referrer-Policy': 'strict-origin-when-cross-origin',
  711. });
  712. result.done(function( data, s, x ){
  713. expect(data).toEqual([]);
  714. done();
  715. });
  716. });
  717. it('should return no message if Referrer-Policy is set to same-origin', function(done) {
  718. protocolStub.returns('https');
  719. var result = OC.SetupChecks.checkGeneric();
  720. suite.server.requests[0].respond(200, {
  721. 'Strict-Transport-Security': 'max-age=15768000',
  722. 'X-XSS-Protection': '1; mode=block',
  723. 'X-Content-Type-Options': 'nosniff',
  724. 'X-Robots-Tag': 'noindex, nofollow',
  725. 'X-Frame-Options': 'SAMEORIGIN',
  726. 'X-Permitted-Cross-Domain-Policies': 'none',
  727. 'Referrer-Policy': 'same-origin',
  728. });
  729. result.done(function( data, s, x ){
  730. expect(data).toEqual([]);
  731. done();
  732. });
  733. });
  734. it('should return a message if Referrer-Policy is set to origin', function(done) {
  735. protocolStub.returns('https');
  736. var result = OC.SetupChecks.checkGeneric();
  737. suite.server.requests[0].respond(200, {
  738. 'Strict-Transport-Security': 'max-age=15768000',
  739. 'X-XSS-Protection': '1; mode=block',
  740. 'X-Content-Type-Options': 'nosniff',
  741. 'X-Robots-Tag': 'noindex, nofollow',
  742. 'X-Frame-Options': 'SAMEORIGIN',
  743. 'X-Permitted-Cross-Domain-Policies': 'none',
  744. 'Referrer-Policy': 'origin',
  745. });
  746. result.done(function( data, s, x ){
  747. expect(data).toEqual([
  748. {
  749. 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>.',
  750. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  751. }
  752. ]);
  753. done();
  754. });
  755. });
  756. it('should return a message if Referrer-Policy is set to origin-when-cross-origin', function(done) {
  757. protocolStub.returns('https');
  758. var result = OC.SetupChecks.checkGeneric();
  759. suite.server.requests[0].respond(200, {
  760. 'Strict-Transport-Security': 'max-age=15768000',
  761. 'X-XSS-Protection': '1; mode=block',
  762. 'X-Content-Type-Options': 'nosniff',
  763. 'X-Robots-Tag': 'noindex, nofollow',
  764. 'X-Frame-Options': 'SAMEORIGIN',
  765. 'X-Permitted-Cross-Domain-Policies': 'none',
  766. 'Referrer-Policy': 'origin-when-cross-origin',
  767. });
  768. result.done(function( data, s, x ){
  769. expect(data).toEqual([
  770. {
  771. 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>.',
  772. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  773. }
  774. ]);
  775. done();
  776. });
  777. });
  778. it('should return a message if Referrer-Policy is set to unsafe-url', function(done) {
  779. protocolStub.returns('https');
  780. var result = OC.SetupChecks.checkGeneric();
  781. suite.server.requests[0].respond(200, {
  782. 'Strict-Transport-Security': 'max-age=15768000',
  783. 'X-XSS-Protection': '1; mode=block',
  784. 'X-Content-Type-Options': 'nosniff',
  785. 'X-Robots-Tag': 'noindex, nofollow',
  786. 'X-Frame-Options': 'SAMEORIGIN',
  787. 'X-Permitted-Cross-Domain-Policies': 'none',
  788. 'Referrer-Policy': 'unsafe-url',
  789. });
  790. result.done(function( data, s, x ){
  791. expect(data).toEqual([
  792. {
  793. 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>.',
  794. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  795. }
  796. ]);
  797. done();
  798. });
  799. });
  800. });
  801. });
  802. it('should return an error if the response has no statuscode 200', function(done) {
  803. var async = OC.SetupChecks.checkGeneric();
  804. suite.server.requests[0].respond(
  805. 500,
  806. {
  807. 'Content-Type': 'application/json'
  808. },
  809. JSON.stringify({data: {serverHasInternetConnectionProblems: true}})
  810. );
  811. async.done(function( data, s, x ){
  812. expect(data).toEqual([{
  813. msg: 'Error occurred while checking server setup',
  814. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  815. }, {
  816. msg: 'Error occurred while checking server setup',
  817. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  818. }]);
  819. done();
  820. });
  821. });
  822. it('should return a SSL warning if SSL used without Strict-Transport-Security-Header', function(done) {
  823. protocolStub.returns('https');
  824. var async = OC.SetupChecks.checkGeneric();
  825. suite.server.requests[0].respond(200,
  826. {
  827. 'X-XSS-Protection': '1; mode=block',
  828. 'X-Content-Type-Options': 'nosniff',
  829. 'X-Robots-Tag': 'noindex, nofollow',
  830. 'X-Frame-Options': 'SAMEORIGIN',
  831. 'X-Permitted-Cross-Domain-Policies': 'none',
  832. 'Referrer-Policy': 'no-referrer',
  833. }
  834. );
  835. async.done(function( data, s, x ){
  836. expect(data).toEqual([{
  837. 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>.',
  838. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  839. }]);
  840. done();
  841. });
  842. });
  843. it('should return a SSL warning if SSL used with to small 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. 'Strict-Transport-Security': 'max-age=15551999',
  849. 'X-XSS-Protection': '1; mode=block',
  850. 'X-Content-Type-Options': 'nosniff',
  851. 'X-Robots-Tag': 'noindex, nofollow',
  852. 'X-Frame-Options': 'SAMEORIGIN',
  853. 'X-Permitted-Cross-Domain-Policies': 'none',
  854. 'Referrer-Policy': 'no-referrer',
  855. }
  856. );
  857. async.done(function( data, s, x ){
  858. expect(data).toEqual([{
  859. 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>.',
  860. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  861. }]);
  862. done();
  863. });
  864. });
  865. it('should return a SSL warning if SSL used with to a bogus Strict-Transport-Security-Header', function(done) {
  866. protocolStub.returns('https');
  867. var async = OC.SetupChecks.checkGeneric();
  868. suite.server.requests[0].respond(200,
  869. {
  870. 'Strict-Transport-Security': 'iAmABogusHeader342',
  871. 'X-XSS-Protection': '1; mode=block',
  872. 'X-Content-Type-Options': 'nosniff',
  873. 'X-Robots-Tag': 'noindex, nofollow',
  874. 'X-Frame-Options': 'SAMEORIGIN',
  875. 'X-Permitted-Cross-Domain-Policies': 'none',
  876. 'Referrer-Policy': 'no-referrer',
  877. }
  878. );
  879. async.done(function( data, s, x ){
  880. expect(data).toEqual([{
  881. 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>.',
  882. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  883. }]);
  884. done();
  885. });
  886. });
  887. it('should return no SSL warning if SSL used with to exact the minimum Strict-Transport-Security-Header', function(done) {
  888. protocolStub.returns('https');
  889. var async = OC.SetupChecks.checkGeneric();
  890. suite.server.requests[0].respond(200, {
  891. 'Strict-Transport-Security': 'max-age=15768000',
  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. async.done(function( data, s, x ){
  900. expect(data).toEqual([]);
  901. done();
  902. });
  903. });
  904. it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header', function(done) {
  905. protocolStub.returns('https');
  906. var async = OC.SetupChecks.checkGeneric();
  907. suite.server.requests[0].respond(200, {
  908. 'Strict-Transport-Security': 'max-age=99999999',
  909. 'X-XSS-Protection': '1; mode=block',
  910. 'X-Content-Type-Options': 'nosniff',
  911. 'X-Robots-Tag': 'noindex, nofollow',
  912. 'X-Frame-Options': 'SAMEORIGIN',
  913. 'X-Permitted-Cross-Domain-Policies': 'none',
  914. 'Referrer-Policy': 'no-referrer',
  915. });
  916. async.done(function( data, s, x ){
  917. expect(data).toEqual([]);
  918. done();
  919. });
  920. });
  921. it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header and includeSubDomains parameter', function(done) {
  922. protocolStub.returns('https');
  923. var async = OC.SetupChecks.checkGeneric();
  924. suite.server.requests[0].respond(200, {
  925. 'Strict-Transport-Security': 'max-age=99999999; includeSubDomains',
  926. 'X-XSS-Protection': '1; mode=block',
  927. 'X-Content-Type-Options': 'nosniff',
  928. 'X-Robots-Tag': 'noindex, nofollow',
  929. 'X-Frame-Options': 'SAMEORIGIN',
  930. 'X-Permitted-Cross-Domain-Policies': 'none',
  931. 'Referrer-Policy': 'no-referrer',
  932. });
  933. async.done(function( data, s, x ){
  934. expect(data).toEqual([]);
  935. done();
  936. });
  937. });
  938. 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) {
  939. protocolStub.returns('https');
  940. var async = OC.SetupChecks.checkGeneric();
  941. suite.server.requests[0].respond(200, {
  942. 'Strict-Transport-Security': 'max-age=99999999; preload; includeSubDomains',
  943. 'X-XSS-Protection': '1; mode=block',
  944. 'X-Content-Type-Options': 'nosniff',
  945. 'X-Robots-Tag': 'noindex, nofollow',
  946. 'X-Frame-Options': 'SAMEORIGIN',
  947. 'X-Permitted-Cross-Domain-Policies': 'none',
  948. 'Referrer-Policy': 'no-referrer',
  949. });
  950. async.done(function( data, s, x ){
  951. expect(data).toEqual([]);
  952. done();
  953. });
  954. });
  955. });