www_spec.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. var chakram = require("./../setup.js").chakram;
  2. var expect = chakram.expect;
  3. // obviously, I took this shamelessly and without further verification from stack overflow
  4. // https://stackoverflow.com/a/17871737
  5. var REGEX_IPV6_ADDRESS = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/;
  6. describe("www/nginx", function () {
  7. before(function () {
  8. var s = chakram.getRequestSettings();
  9. s.followRedirect = false;
  10. s.baseUrl = '';
  11. chakram.setRequestSettings(s);
  12. });
  13. describe("dedyn host", function () {
  14. before(function () {
  15. chakram.setRequestHeader('Host', 'dedyn.' + process.env.DESECSTACK_DOMAIN);
  16. });
  17. it("redirects to the desec host", function () {
  18. [
  19. 'https://' + process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.128/',
  20. 'http://' + process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.128/',
  21. 'https://[' + process.env.DESECSTACK_IPV6_ADDRESS + ']/',
  22. 'http://[' + process.env.DESECSTACK_IPV6_ADDRESS + ']/',
  23. ].forEach(function (url) {
  24. var response = chakram.get(url);
  25. expect(response).to.have.status(301);
  26. expect(response).to.have.header('Location', 'https://desec.' + process.env.DESECSTACK_DOMAIN + '/');
  27. });
  28. return chakram.wait();
  29. });
  30. });
  31. describe("checkip.dedyn host", function () {
  32. before(function () {
  33. chakram.setRequestHeader('Host', 'checkip.dedyn.' + process.env.DESECSTACK_DOMAIN);
  34. });
  35. describe("contacted through SSL/TLS", function () {
  36. it('returns the ipv4 address when contacted through ipv4', function () {
  37. var response = chakram.get('https://' + process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.128/');
  38. return expect(response).to.have.body(process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.127');
  39. });
  40. it('returns an ipv6 address when contacted through ipv6', function () {
  41. var response = chakram.get('https://[' + process.env.DESECSTACK_IPV6_ADDRESS + ']/');
  42. // it's hard to find out which IPv6 address we actually expect here
  43. // and as we are inside the docker network anyway (that is, we are
  44. // topologically not in the same place as the end user), it's hard
  45. // if the correct address is returned. Hence, we will stick to some
  46. // simple tests.
  47. expect(response).to.have.body(REGEX_IPV6_ADDRESS);
  48. return chakram.wait();
  49. });
  50. });
  51. describe("contacted without encryption", function () {
  52. it('redirects to SSL/TLS when contacted through ipv4', function () {
  53. var response = chakram.get('http://' + process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.128/');
  54. expect(response).to.have.status(301);
  55. expect(response).to.have.header('Location', 'https://checkip.dedyn.' + process.env.DESECSTACK_DOMAIN + '/');
  56. return chakram.wait();
  57. });
  58. it('redirects to SSL/TLS when contacted through ipv6', function () {
  59. var response = chakram.get('http://[' + process.env.DESECSTACK_IPV6_ADDRESS + ']/');
  60. expect(response).to.have.status(301);
  61. expect(response).to.have.header('Location', 'https://checkip.dedyn.' + process.env.DESECSTACK_DOMAIN + '/');
  62. return chakram.wait();
  63. });
  64. });
  65. });
  66. describe("checkipv4.dedyn host", function () {
  67. before(function () {
  68. chakram.setRequestHeader('Host', 'checkipv4.dedyn.' + process.env.DESECSTACK_DOMAIN);
  69. });
  70. it('returns the ipv4 address when contacted through ipv4', function () {
  71. var response = chakram.get('https://' + process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.128/');
  72. return expect(response).to.have.body(process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.127');
  73. });
  74. it('redirects to SSL/TLS when concated without encryption', function () {
  75. var response = chakram.get('http://' + process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.128/');
  76. expect(response).to.have.status(301);
  77. expect(response).to.have.header('Location', 'https://checkipv4.dedyn.' + process.env.DESECSTACK_DOMAIN + '/');
  78. return chakram.wait();
  79. });
  80. it('closes the connection when contacted through ipv6', function () {
  81. var response = chakram.get('https://[' + process.env.DESECSTACK_IPV6_ADDRESS + ']/');
  82. return expect(response).to.not.have.a.body();
  83. });
  84. });
  85. describe("checkipv6.dedyn host", function () {
  86. before(function () {
  87. chakram.setRequestHeader('Host', 'checkipv6.dedyn.' + process.env.DESECSTACK_DOMAIN);
  88. });
  89. it('closes the connection when contacted through ipv4', function () {
  90. var response = chakram.get('https://' + process.env.DESECSTACK_IPV4_REAR_PREFIX16 + '.0.128/');
  91. return expect(response).to.not.have.a.body();
  92. });
  93. it('redirects to SSL/TLS when concated without encryption', function () {
  94. var response = chakram.get('http://[' + process.env.DESECSTACK_IPV6_ADDRESS + ']/');
  95. expect(response).to.have.status(301);
  96. expect(response).to.have.header('Location', 'https://checkipv6.dedyn.' + process.env.DESECSTACK_DOMAIN + '/');
  97. return chakram.wait();
  98. });
  99. it('returns an ipv6 address when contacted through ipv6', function () {
  100. var response = chakram.get('https://[' + process.env.DESECSTACK_IPV6_ADDRESS + ']/');
  101. // it's hard to find out which IPv6 address we actually expect here
  102. // and as we are inside the docker network anyway (that is, we are
  103. // topologically not in the same place as the end user), it's hard
  104. // if the correct address is returned. Hence, we will stick to some
  105. // simple tests.
  106. expect(response).to.have.body(REGEX_IPV6_ADDRESS);
  107. return chakram.wait();
  108. });
  109. });
  110. describe("desec host", function () {
  111. before(function () {
  112. chakram.setRequestHeader('Host', 'desec.' + process.env.DESECSTACK_DOMAIN);
  113. });
  114. it("is alive", function () {
  115. var response = chakram.get('https://www/');
  116. return expect(response).to.have.status(200);
  117. });
  118. });
  119. });