setupchecksSpec.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  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('checkSetup', function() {
  51. it('should return an error if server has no internet connection', function(done) {
  52. var async = OC.SetupChecks.checkSetup();
  53. suite.server.requests[0].respond(
  54. 200,
  55. {
  56. 'Content-Type': 'application/json'
  57. },
  58. JSON.stringify({
  59. generic: {
  60. network: {
  61. "Internet connectivity": {
  62. severity: "warning",
  63. 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.',
  64. linkToDoc: null
  65. }
  66. },
  67. },
  68. })
  69. );
  70. async.done(function( data, s, x ){
  71. expect(data).toEqual([
  72. {
  73. 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.',
  74. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  75. },
  76. ]);
  77. done();
  78. });
  79. });
  80. it('should return an error if server has no internet connection and data directory is not protected', function(done) {
  81. var async = OC.SetupChecks.checkSetup();
  82. suite.server.requests[0].respond(
  83. 200,
  84. {
  85. 'Content-Type': 'application/json'
  86. },
  87. JSON.stringify({
  88. generic: {
  89. network: {
  90. "Internet connectivity": {
  91. severity: "warning",
  92. 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.',
  93. linkToDoc: null
  94. }
  95. },
  96. },
  97. })
  98. );
  99. async.done(function( data, s, x ){
  100. expect(data).toEqual([
  101. {
  102. 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.',
  103. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  104. },
  105. ]);
  106. done();
  107. });
  108. });
  109. it('should return an error if server has no internet connection and data directory is not protected and memcache is available', function(done) {
  110. var async = OC.SetupChecks.checkSetup();
  111. suite.server.requests[0].respond(
  112. 200,
  113. {
  114. 'Content-Type': 'application/json',
  115. },
  116. JSON.stringify({
  117. generic: {
  118. network: {
  119. "Internet connectivity": {
  120. severity: "warning",
  121. 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.',
  122. linkToDoc: null
  123. }
  124. },
  125. },
  126. })
  127. );
  128. async.done(function( data, s, x ){
  129. expect(data).toEqual([
  130. {
  131. 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.',
  132. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  133. }
  134. ]);
  135. done();
  136. });
  137. });
  138. it('should return a warning if the memory limit is below the recommended value', function(done) {
  139. var async = OC.SetupChecks.checkSetup();
  140. suite.server.requests[0].respond(
  141. 200,
  142. {
  143. 'Content-Type': 'application/json',
  144. },
  145. JSON.stringify({
  146. generic: {
  147. network: {
  148. "Internet connectivity": {
  149. severity: "success",
  150. description: null,
  151. linkToDoc: null
  152. }
  153. },
  154. php: {
  155. "Internet connectivity": {
  156. severity: "success",
  157. description: null,
  158. linkToDoc: null
  159. },
  160. "PHP memory limit": {
  161. severity: "error",
  162. description: "The PHP memory limit is below the recommended value of 512MB.",
  163. linkToDoc: null
  164. },
  165. },
  166. },
  167. })
  168. );
  169. async.done(function( data, s, x ){
  170. expect(data).toEqual([{
  171. msg: 'The PHP memory limit is below the recommended value of 512MB.',
  172. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  173. }]);
  174. done();
  175. });
  176. });
  177. it('should return an error if the response has no statuscode 200', function(done) {
  178. var async = OC.SetupChecks.checkSetup();
  179. suite.server.requests[0].respond(
  180. 500,
  181. {
  182. 'Content-Type': 'application/json'
  183. },
  184. JSON.stringify({data: {serverHasInternetConnectionProblems: true}})
  185. );
  186. async.done(function( data, s, x ){
  187. expect(data).toEqual([{
  188. msg: 'Error occurred while checking server setup',
  189. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  190. }]);
  191. done();
  192. });
  193. });
  194. it('should return an error if the php version is no longer supported', function(done) {
  195. var async = OC.SetupChecks.checkSetup();
  196. suite.server.requests[0].respond(
  197. 200,
  198. {
  199. 'Content-Type': 'application/json',
  200. },
  201. JSON.stringify({
  202. generic: {
  203. network: {
  204. "Internet connectivity": {
  205. severity: "success",
  206. description: null,
  207. linkToDoc: null
  208. }
  209. },
  210. security: {
  211. "Checking for PHP version": {
  212. severity: "warning",
  213. 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.",
  214. linkToDoc: "https://secure.php.net/supported-versions.php"
  215. }
  216. },
  217. },
  218. })
  219. );
  220. async.done(function( data, s, x ){
  221. expect(data).toEqual([{
  222. 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>.',
  223. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  224. }]);
  225. done();
  226. });
  227. });
  228. it('should not return an error if the protocol is http and the server generates http links', function(done) {
  229. var async = OC.SetupChecks.checkSetup();
  230. suite.server.requests[0].respond(
  231. 200,
  232. {
  233. 'Content-Type': 'application/json',
  234. },
  235. JSON.stringify({
  236. generic: {
  237. network: {
  238. "Internet connectivity": {
  239. severity: "success",
  240. description: null,
  241. linkToDoc: null
  242. }
  243. },
  244. },
  245. })
  246. );
  247. async.done(function( data, s, x ){
  248. expect(data).toEqual([]);
  249. done();
  250. });
  251. });
  252. it('should return an info if there is no default phone region', function(done) {
  253. var async = OC.SetupChecks.checkSetup();
  254. suite.server.requests[0].respond(
  255. 200,
  256. {
  257. 'Content-Type': 'application/json',
  258. },
  259. JSON.stringify({
  260. generic: {
  261. network: {
  262. "Internet connectivity": {
  263. severity: "success",
  264. description: null,
  265. linkToDoc: null
  266. }
  267. },
  268. config: {
  269. "Checking for default phone region": {
  270. severity: "info",
  271. 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.",
  272. linkToDoc: "https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements"
  273. },
  274. },
  275. },
  276. })
  277. );
  278. async.done(function( data, s, x ){
  279. expect(data).toEqual([{
  280. 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>.',
  281. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  282. }]);
  283. done();
  284. });
  285. });
  286. });
  287. describe('checkGeneric', function() {
  288. it('should return an error if the response has no statuscode 200', function(done) {
  289. var async = OC.SetupChecks.checkGeneric();
  290. suite.server.requests[0].respond(
  291. 500,
  292. {
  293. 'Content-Type': 'application/json'
  294. }
  295. );
  296. async.done(function( data, s, x ){
  297. expect(data).toEqual([{
  298. msg: 'Error occurred while checking server setup',
  299. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  300. },{
  301. msg: 'Error occurred while checking server setup',
  302. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  303. }]);
  304. done();
  305. });
  306. });
  307. it('should return all errors if all headers are missing', function(done) {
  308. protocolStub.returns('https');
  309. var async = OC.SetupChecks.checkGeneric();
  310. suite.server.requests[0].respond(
  311. 200,
  312. {
  313. 'Content-Type': 'application/json',
  314. 'Strict-Transport-Security': 'max-age=15768000'
  315. },
  316. '{}'
  317. );
  318. async.done(function( data, s, x ){
  319. expect(data).toEqual([
  320. {
  321. 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.',
  322. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  323. }, {
  324. 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.',
  325. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  326. }, {
  327. 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.',
  328. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  329. }, {
  330. 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.',
  331. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  332. }, {
  333. 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.',
  334. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  335. }, {
  336. 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>.',
  337. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  338. }
  339. ]);
  340. done();
  341. });
  342. });
  343. it('should return only some errors if just some headers are missing', function(done) {
  344. protocolStub.returns('https');
  345. var async = OC.SetupChecks.checkGeneric();
  346. suite.server.requests[0].respond(
  347. 200,
  348. {
  349. 'X-Robots-Tag': 'noindex, nofollow',
  350. 'X-Frame-Options': 'SAMEORIGIN',
  351. 'Strict-Transport-Security': 'max-age=15768000;preload',
  352. 'X-Permitted-Cross-Domain-Policies': 'none',
  353. 'Referrer-Policy': 'no-referrer',
  354. }
  355. );
  356. async.done(function( data, s, x ){
  357. expect(data).toEqual([
  358. {
  359. 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.',
  360. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  361. }, {
  362. 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.',
  363. type: OC.SetupChecks.MESSAGE_TYPE_WARNING,
  364. }
  365. ]);
  366. done();
  367. });
  368. });
  369. it('should return none errors if all headers are there', function(done) {
  370. protocolStub.returns('https');
  371. var async = OC.SetupChecks.checkGeneric();
  372. suite.server.requests[0].respond(
  373. 200,
  374. {
  375. 'X-XSS-Protection': '1; mode=block',
  376. 'X-Content-Type-Options': 'nosniff',
  377. 'X-Robots-Tag': 'noindex, nofollow',
  378. 'X-Frame-Options': 'SAMEORIGIN',
  379. 'Strict-Transport-Security': 'max-age=15768000',
  380. 'X-Permitted-Cross-Domain-Policies': 'none',
  381. 'Referrer-Policy': 'no-referrer'
  382. }
  383. );
  384. async.done(function( data, s, x ){
  385. expect(data).toEqual([]);
  386. done();
  387. });
  388. });
  389. describe('check X-Robots-Tag header', function() {
  390. it('should return no message if X-Robots-Tag is set to noindex,nofollow without space', function(done) {
  391. protocolStub.returns('https');
  392. var result = OC.SetupChecks.checkGeneric();
  393. suite.server.requests[0].respond(200, {
  394. 'Strict-Transport-Security': 'max-age=15768000',
  395. 'X-XSS-Protection': '1; mode=block',
  396. 'X-Content-Type-Options': 'nosniff',
  397. 'X-Robots-Tag': 'noindex,nofollow',
  398. 'X-Frame-Options': 'SAMEORIGIN',
  399. 'X-Permitted-Cross-Domain-Policies': 'none',
  400. 'Referrer-Policy': 'no-referrer',
  401. });
  402. result.done(function( data, s, x ){
  403. expect(data).toEqual([]);
  404. done();
  405. });
  406. });
  407. it('should return a message if X-Robots-Tag is set to none', function(done) {
  408. protocolStub.returns('https');
  409. var result = OC.SetupChecks.checkGeneric();
  410. suite.server.requests[0].respond(200, {
  411. 'Strict-Transport-Security': 'max-age=15768000',
  412. 'X-XSS-Protection': '1; mode=block',
  413. 'X-Content-Type-Options': 'nosniff',
  414. 'X-Robots-Tag': 'none',
  415. 'X-Frame-Options': 'SAMEORIGIN',
  416. 'X-Permitted-Cross-Domain-Policies': 'none',
  417. 'Referrer-Policy': 'no-referrer',
  418. });
  419. result.done(function( data, s, x ){
  420. expect(data).toEqual([
  421. {
  422. 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.',
  423. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  424. }
  425. ]);
  426. done();
  427. });
  428. });
  429. });
  430. describe('check X-XSS-Protection header', function() {
  431. it('should return no message if X-XSS-Protection is set to 1; mode=block; report=https://example.com', function(done) {
  432. protocolStub.returns('https');
  433. var result = OC.SetupChecks.checkGeneric();
  434. suite.server.requests[0].respond(200, {
  435. 'Strict-Transport-Security': 'max-age=15768000',
  436. 'X-XSS-Protection': '1; mode=block; report=https://example.com',
  437. 'X-Content-Type-Options': 'nosniff',
  438. 'X-Robots-Tag': 'noindex, nofollow',
  439. 'X-Frame-Options': 'SAMEORIGIN',
  440. 'X-Permitted-Cross-Domain-Policies': 'none',
  441. 'Referrer-Policy': 'no-referrer',
  442. });
  443. result.done(function( data, s, x ){
  444. expect(data).toEqual([]);
  445. done();
  446. });
  447. });
  448. it('should return no message if X-XSS-Protection is set to 1; mode=block', function(done) {
  449. protocolStub.returns('https');
  450. var result = OC.SetupChecks.checkGeneric();
  451. suite.server.requests[0].respond(200, {
  452. 'Strict-Transport-Security': 'max-age=15768000',
  453. 'X-XSS-Protection': '1; mode=block',
  454. 'X-Content-Type-Options': 'nosniff',
  455. 'X-Robots-Tag': 'noindex, nofollow',
  456. 'X-Frame-Options': 'SAMEORIGIN',
  457. 'X-Permitted-Cross-Domain-Policies': 'none',
  458. 'Referrer-Policy': 'no-referrer',
  459. });
  460. result.done(function( data, s, x ){
  461. expect(data).toEqual([]);
  462. done();
  463. });
  464. });
  465. it('should return a message if X-XSS-Protection is set to 1', function(done) {
  466. protocolStub.returns('https');
  467. var result = OC.SetupChecks.checkGeneric();
  468. suite.server.requests[0].respond(200, {
  469. 'Strict-Transport-Security': 'max-age=15768000',
  470. 'X-XSS-Protection': '1',
  471. 'X-Content-Type-Options': 'nosniff',
  472. 'X-Robots-Tag': 'noindex, nofollow',
  473. 'X-Frame-Options': 'SAMEORIGIN',
  474. 'X-Permitted-Cross-Domain-Policies': 'none',
  475. 'Referrer-Policy': 'no-referrer',
  476. });
  477. result.done(function( data, s, x ){
  478. expect(data).toEqual([
  479. {
  480. 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.',
  481. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  482. }
  483. ]);
  484. done();
  485. });
  486. });
  487. it('should return a message if X-XSS-Protection is set to 0', function(done) {
  488. protocolStub.returns('https');
  489. var result = OC.SetupChecks.checkGeneric();
  490. suite.server.requests[0].respond(200, {
  491. 'Strict-Transport-Security': 'max-age=15768000',
  492. 'X-XSS-Protection': '0',
  493. 'X-Content-Type-Options': 'nosniff',
  494. 'X-Robots-Tag': 'noindex, nofollow',
  495. 'X-Frame-Options': 'SAMEORIGIN',
  496. 'X-Permitted-Cross-Domain-Policies': 'none',
  497. 'Referrer-Policy': 'no-referrer',
  498. });
  499. result.done(function( data, s, x ){
  500. expect(data).toEqual([
  501. {
  502. 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.',
  503. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  504. }
  505. ]);
  506. done();
  507. });
  508. });
  509. });
  510. describe('check Referrer-Policy header', function() {
  511. it('should return no message if Referrer-Policy is set to no-referrer', function(done) {
  512. protocolStub.returns('https');
  513. var result = OC.SetupChecks.checkGeneric();
  514. suite.server.requests[0].respond(200, {
  515. 'Strict-Transport-Security': 'max-age=15768000',
  516. 'X-XSS-Protection': '1; mode=block',
  517. 'X-Content-Type-Options': 'nosniff',
  518. 'X-Robots-Tag': 'noindex, nofollow',
  519. 'X-Frame-Options': 'SAMEORIGIN',
  520. 'X-Permitted-Cross-Domain-Policies': 'none',
  521. 'Referrer-Policy': 'no-referrer',
  522. });
  523. result.done(function( data, s, x ){
  524. expect(data).toEqual([]);
  525. done();
  526. });
  527. });
  528. it('should return no message if Referrer-Policy is set to no-referrer-when-downgrade', 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-when-downgrade',
  539. });
  540. result.done(function( data, s, x ){
  541. expect(data).toEqual([]);
  542. done();
  543. });
  544. });
  545. it('should return no message if Referrer-Policy is set to strict-origin', 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': 'noindex, nofollow',
  553. 'X-Frame-Options': 'SAMEORIGIN',
  554. 'X-Permitted-Cross-Domain-Policies': 'none',
  555. 'Referrer-Policy': 'strict-origin',
  556. });
  557. result.done(function( data, s, x ){
  558. expect(data).toEqual([]);
  559. done();
  560. });
  561. });
  562. it('should return no message if Referrer-Policy is set to strict-origin-when-cross-origin', function(done) {
  563. protocolStub.returns('https');
  564. var result = OC.SetupChecks.checkGeneric();
  565. suite.server.requests[0].respond(200, {
  566. 'Strict-Transport-Security': 'max-age=15768000',
  567. 'X-XSS-Protection': '1; mode=block',
  568. 'X-Content-Type-Options': 'nosniff',
  569. 'X-Robots-Tag': 'noindex, nofollow',
  570. 'X-Frame-Options': 'SAMEORIGIN',
  571. 'X-Permitted-Cross-Domain-Policies': 'none',
  572. 'Referrer-Policy': 'strict-origin-when-cross-origin',
  573. });
  574. result.done(function( data, s, x ){
  575. expect(data).toEqual([]);
  576. done();
  577. });
  578. });
  579. it('should return no message if Referrer-Policy is set to same-origin', function(done) {
  580. protocolStub.returns('https');
  581. var result = OC.SetupChecks.checkGeneric();
  582. suite.server.requests[0].respond(200, {
  583. 'Strict-Transport-Security': 'max-age=15768000',
  584. 'X-XSS-Protection': '1; mode=block',
  585. 'X-Content-Type-Options': 'nosniff',
  586. 'X-Robots-Tag': 'noindex, nofollow',
  587. 'X-Frame-Options': 'SAMEORIGIN',
  588. 'X-Permitted-Cross-Domain-Policies': 'none',
  589. 'Referrer-Policy': 'same-origin',
  590. });
  591. result.done(function( data, s, x ){
  592. expect(data).toEqual([]);
  593. done();
  594. });
  595. });
  596. it('should return a message if Referrer-Policy is set to origin', function(done) {
  597. protocolStub.returns('https');
  598. var result = OC.SetupChecks.checkGeneric();
  599. suite.server.requests[0].respond(200, {
  600. 'Strict-Transport-Security': 'max-age=15768000',
  601. 'X-XSS-Protection': '1; mode=block',
  602. 'X-Content-Type-Options': 'nosniff',
  603. 'X-Robots-Tag': 'noindex, nofollow',
  604. 'X-Frame-Options': 'SAMEORIGIN',
  605. 'X-Permitted-Cross-Domain-Policies': 'none',
  606. 'Referrer-Policy': 'origin',
  607. });
  608. result.done(function( data, s, x ){
  609. expect(data).toEqual([
  610. {
  611. 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>.',
  612. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  613. }
  614. ]);
  615. done();
  616. });
  617. });
  618. it('should return a message if Referrer-Policy is set to origin-when-cross-origin', function(done) {
  619. protocolStub.returns('https');
  620. var result = OC.SetupChecks.checkGeneric();
  621. suite.server.requests[0].respond(200, {
  622. 'Strict-Transport-Security': 'max-age=15768000',
  623. 'X-XSS-Protection': '1; mode=block',
  624. 'X-Content-Type-Options': 'nosniff',
  625. 'X-Robots-Tag': 'noindex, nofollow',
  626. 'X-Frame-Options': 'SAMEORIGIN',
  627. 'X-Permitted-Cross-Domain-Policies': 'none',
  628. 'Referrer-Policy': 'origin-when-cross-origin',
  629. });
  630. result.done(function( data, s, x ){
  631. expect(data).toEqual([
  632. {
  633. 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>.',
  634. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  635. }
  636. ]);
  637. done();
  638. });
  639. });
  640. it('should return a message if Referrer-Policy is set to unsafe-url', function(done) {
  641. protocolStub.returns('https');
  642. var result = OC.SetupChecks.checkGeneric();
  643. suite.server.requests[0].respond(200, {
  644. 'Strict-Transport-Security': 'max-age=15768000',
  645. 'X-XSS-Protection': '1; mode=block',
  646. 'X-Content-Type-Options': 'nosniff',
  647. 'X-Robots-Tag': 'noindex, nofollow',
  648. 'X-Frame-Options': 'SAMEORIGIN',
  649. 'X-Permitted-Cross-Domain-Policies': 'none',
  650. 'Referrer-Policy': 'unsafe-url',
  651. });
  652. result.done(function( data, s, x ){
  653. expect(data).toEqual([
  654. {
  655. 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>.',
  656. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  657. }
  658. ]);
  659. done();
  660. });
  661. });
  662. });
  663. });
  664. it('should return an error if the response has no statuscode 200', function(done) {
  665. var async = OC.SetupChecks.checkGeneric();
  666. suite.server.requests[0].respond(
  667. 500,
  668. {
  669. 'Content-Type': 'application/json'
  670. },
  671. JSON.stringify({data: {serverHasInternetConnectionProblems: true}})
  672. );
  673. async.done(function( data, s, x ){
  674. expect(data).toEqual([{
  675. msg: 'Error occurred while checking server setup',
  676. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  677. }, {
  678. msg: 'Error occurred while checking server setup',
  679. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  680. }]);
  681. done();
  682. });
  683. });
  684. it('should return a SSL warning if SSL used without Strict-Transport-Security-Header', function(done) {
  685. protocolStub.returns('https');
  686. var async = OC.SetupChecks.checkGeneric();
  687. suite.server.requests[0].respond(200,
  688. {
  689. 'X-XSS-Protection': '1; mode=block',
  690. 'X-Content-Type-Options': 'nosniff',
  691. 'X-Robots-Tag': 'noindex, nofollow',
  692. 'X-Frame-Options': 'SAMEORIGIN',
  693. 'X-Permitted-Cross-Domain-Policies': 'none',
  694. 'Referrer-Policy': 'no-referrer',
  695. }
  696. );
  697. async.done(function( data, s, x ){
  698. expect(data).toEqual([{
  699. 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>.',
  700. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  701. }]);
  702. done();
  703. });
  704. });
  705. it('should return a SSL warning if SSL used with to small Strict-Transport-Security-Header', function(done) {
  706. protocolStub.returns('https');
  707. var async = OC.SetupChecks.checkGeneric();
  708. suite.server.requests[0].respond(200,
  709. {
  710. 'Strict-Transport-Security': 'max-age=15551999',
  711. 'X-XSS-Protection': '1; mode=block',
  712. 'X-Content-Type-Options': 'nosniff',
  713. 'X-Robots-Tag': 'noindex, nofollow',
  714. 'X-Frame-Options': 'SAMEORIGIN',
  715. 'X-Permitted-Cross-Domain-Policies': 'none',
  716. 'Referrer-Policy': 'no-referrer',
  717. }
  718. );
  719. async.done(function( data, s, x ){
  720. expect(data).toEqual([{
  721. 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>.',
  722. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  723. }]);
  724. done();
  725. });
  726. });
  727. it('should return a SSL warning if SSL used with to a bogus Strict-Transport-Security-Header', function(done) {
  728. protocolStub.returns('https');
  729. var async = OC.SetupChecks.checkGeneric();
  730. suite.server.requests[0].respond(200,
  731. {
  732. 'Strict-Transport-Security': 'iAmABogusHeader342',
  733. 'X-XSS-Protection': '1; mode=block',
  734. 'X-Content-Type-Options': 'nosniff',
  735. 'X-Robots-Tag': 'noindex, nofollow',
  736. 'X-Frame-Options': 'SAMEORIGIN',
  737. 'X-Permitted-Cross-Domain-Policies': 'none',
  738. 'Referrer-Policy': 'no-referrer',
  739. }
  740. );
  741. async.done(function( data, s, x ){
  742. expect(data).toEqual([{
  743. 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>.',
  744. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  745. }]);
  746. done();
  747. });
  748. });
  749. it('should return no SSL warning if SSL used with to exact the minimum Strict-Transport-Security-Header', function(done) {
  750. protocolStub.returns('https');
  751. var async = OC.SetupChecks.checkGeneric();
  752. suite.server.requests[0].respond(200, {
  753. 'Strict-Transport-Security': 'max-age=15768000',
  754. 'X-XSS-Protection': '1; mode=block',
  755. 'X-Content-Type-Options': 'nosniff',
  756. 'X-Robots-Tag': 'noindex, nofollow',
  757. 'X-Frame-Options': 'SAMEORIGIN',
  758. 'X-Permitted-Cross-Domain-Policies': 'none',
  759. 'Referrer-Policy': 'no-referrer',
  760. });
  761. async.done(function( data, s, x ){
  762. expect(data).toEqual([]);
  763. done();
  764. });
  765. });
  766. it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header', function(done) {
  767. protocolStub.returns('https');
  768. var async = OC.SetupChecks.checkGeneric();
  769. suite.server.requests[0].respond(200, {
  770. 'Strict-Transport-Security': 'max-age=99999999',
  771. 'X-XSS-Protection': '1; mode=block',
  772. 'X-Content-Type-Options': 'nosniff',
  773. 'X-Robots-Tag': 'noindex, nofollow',
  774. 'X-Frame-Options': 'SAMEORIGIN',
  775. 'X-Permitted-Cross-Domain-Policies': 'none',
  776. 'Referrer-Policy': 'no-referrer',
  777. });
  778. async.done(function( data, s, x ){
  779. expect(data).toEqual([]);
  780. done();
  781. });
  782. });
  783. it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header and includeSubDomains parameter', function(done) {
  784. protocolStub.returns('https');
  785. var async = OC.SetupChecks.checkGeneric();
  786. suite.server.requests[0].respond(200, {
  787. 'Strict-Transport-Security': 'max-age=99999999; includeSubDomains',
  788. 'X-XSS-Protection': '1; mode=block',
  789. 'X-Content-Type-Options': 'nosniff',
  790. 'X-Robots-Tag': 'noindex, nofollow',
  791. 'X-Frame-Options': 'SAMEORIGIN',
  792. 'X-Permitted-Cross-Domain-Policies': 'none',
  793. 'Referrer-Policy': 'no-referrer',
  794. });
  795. async.done(function( data, s, x ){
  796. expect(data).toEqual([]);
  797. done();
  798. });
  799. });
  800. 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) {
  801. protocolStub.returns('https');
  802. var async = OC.SetupChecks.checkGeneric();
  803. suite.server.requests[0].respond(200, {
  804. 'Strict-Transport-Security': 'max-age=99999999; preload; includeSubDomains',
  805. 'X-XSS-Protection': '1; mode=block',
  806. 'X-Content-Type-Options': 'nosniff',
  807. 'X-Robots-Tag': 'noindex, nofollow',
  808. 'X-Frame-Options': 'SAMEORIGIN',
  809. 'X-Permitted-Cross-Domain-Policies': 'none',
  810. 'Referrer-Policy': 'no-referrer',
  811. });
  812. async.done(function( data, s, x ){
  813. expect(data).toEqual([]);
  814. done();
  815. });
  816. });
  817. });