setupchecksSpec.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**
  2. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2015 ownCloud Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. describe('OC.SetupChecks tests', function() {
  7. var suite = this;
  8. var protocolStub;
  9. beforeEach( function(){
  10. protocolStub = sinon.stub(OC, 'getProtocol');
  11. suite.server = sinon.fakeServer.create();
  12. });
  13. afterEach( function(){
  14. suite.server.restore();
  15. protocolStub.restore();
  16. });
  17. describe('checkSetup', function() {
  18. it('should return an error if server has no internet connection', function(done) {
  19. var async = OC.SetupChecks.checkSetup();
  20. suite.server.requests[0].respond(
  21. 200,
  22. {
  23. 'Content-Type': 'application/json'
  24. },
  25. JSON.stringify({
  26. generic: {
  27. network: {
  28. "Internet connectivity": {
  29. severity: "warning",
  30. 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.',
  31. linkToDoc: null
  32. }
  33. },
  34. },
  35. })
  36. );
  37. async.done(function( data, s, x ){
  38. expect(data).toEqual([
  39. {
  40. 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.',
  41. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  42. },
  43. ]);
  44. done();
  45. });
  46. });
  47. it('should return an error if server has no internet connection and data directory is not protected', function(done) {
  48. var async = OC.SetupChecks.checkSetup();
  49. suite.server.requests[0].respond(
  50. 200,
  51. {
  52. 'Content-Type': 'application/json'
  53. },
  54. JSON.stringify({
  55. generic: {
  56. network: {
  57. "Internet connectivity": {
  58. severity: "warning",
  59. 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.',
  60. linkToDoc: null
  61. }
  62. },
  63. },
  64. })
  65. );
  66. async.done(function( data, s, x ){
  67. expect(data).toEqual([
  68. {
  69. 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.',
  70. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  71. },
  72. ]);
  73. done();
  74. });
  75. });
  76. it('should return an error if server has no internet connection and data directory is not protected and memcache is available', function(done) {
  77. var async = OC.SetupChecks.checkSetup();
  78. suite.server.requests[0].respond(
  79. 200,
  80. {
  81. 'Content-Type': 'application/json',
  82. },
  83. JSON.stringify({
  84. generic: {
  85. network: {
  86. "Internet connectivity": {
  87. severity: "warning",
  88. 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.',
  89. linkToDoc: null
  90. }
  91. },
  92. },
  93. })
  94. );
  95. async.done(function( data, s, x ){
  96. expect(data).toEqual([
  97. {
  98. 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.',
  99. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  100. }
  101. ]);
  102. done();
  103. });
  104. });
  105. it('should return a warning if the memory limit is below the recommended value', function(done) {
  106. var async = OC.SetupChecks.checkSetup();
  107. suite.server.requests[0].respond(
  108. 200,
  109. {
  110. 'Content-Type': 'application/json',
  111. },
  112. JSON.stringify({
  113. generic: {
  114. network: {
  115. "Internet connectivity": {
  116. severity: "success",
  117. description: null,
  118. linkToDoc: null
  119. }
  120. },
  121. php: {
  122. "Internet connectivity": {
  123. severity: "success",
  124. description: null,
  125. linkToDoc: null
  126. },
  127. "PHP memory limit": {
  128. severity: "error",
  129. description: "The PHP memory limit is below the recommended value of 512MB.",
  130. linkToDoc: null
  131. },
  132. },
  133. },
  134. })
  135. );
  136. async.done(function( data, s, x ){
  137. expect(data).toEqual([{
  138. msg: 'The PHP memory limit is below the recommended value of 512MB.',
  139. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  140. }]);
  141. done();
  142. });
  143. });
  144. it('should return an error if the response has no statuscode 200', function(done) {
  145. var async = OC.SetupChecks.checkSetup();
  146. suite.server.requests[0].respond(
  147. 500,
  148. {
  149. 'Content-Type': 'application/json'
  150. },
  151. JSON.stringify({data: {serverHasInternetConnectionProblems: true}})
  152. );
  153. async.done(function( data, s, x ){
  154. expect(data).toEqual([{
  155. msg: 'Error occurred while checking server setup',
  156. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  157. }]);
  158. done();
  159. });
  160. });
  161. it('should return an error if the php version is no longer supported', function(done) {
  162. var async = OC.SetupChecks.checkSetup();
  163. suite.server.requests[0].respond(
  164. 200,
  165. {
  166. 'Content-Type': 'application/json',
  167. },
  168. JSON.stringify({
  169. generic: {
  170. network: {
  171. "Internet connectivity": {
  172. severity: "success",
  173. description: null,
  174. linkToDoc: null
  175. }
  176. },
  177. security: {
  178. "Checking for PHP version": {
  179. severity: "warning",
  180. 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.",
  181. linkToDoc: "https://secure.php.net/supported-versions.php"
  182. }
  183. },
  184. },
  185. })
  186. );
  187. async.done(function( data, s, x ){
  188. expect(data).toEqual([{
  189. 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>.',
  190. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  191. }]);
  192. done();
  193. });
  194. });
  195. it('should not return an error if the protocol is http and the server generates http links', function(done) {
  196. var async = OC.SetupChecks.checkSetup();
  197. suite.server.requests[0].respond(
  198. 200,
  199. {
  200. 'Content-Type': 'application/json',
  201. },
  202. JSON.stringify({
  203. generic: {
  204. network: {
  205. "Internet connectivity": {
  206. severity: "success",
  207. description: null,
  208. linkToDoc: null
  209. }
  210. },
  211. },
  212. })
  213. );
  214. async.done(function( data, s, x ){
  215. expect(data).toEqual([]);
  216. done();
  217. });
  218. });
  219. it('should return an info if there is no default phone region', function(done) {
  220. var async = OC.SetupChecks.checkSetup();
  221. suite.server.requests[0].respond(
  222. 200,
  223. {
  224. 'Content-Type': 'application/json',
  225. },
  226. JSON.stringify({
  227. generic: {
  228. network: {
  229. "Internet connectivity": {
  230. severity: "success",
  231. description: null,
  232. linkToDoc: null
  233. }
  234. },
  235. config: {
  236. "Checking for default phone region": {
  237. severity: "info",
  238. 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.",
  239. linkToDoc: "https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements"
  240. },
  241. },
  242. },
  243. })
  244. );
  245. async.done(function( data, s, x ){
  246. expect(data).toEqual([{
  247. 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>.',
  248. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  249. }]);
  250. done();
  251. });
  252. });
  253. });
  254. });