You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

https_spec.rb 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. describe CryptCheck::Tls::Https do
  2. def server(*args, **kargs, &block)
  3. tls_serv *args, **kargs, &block
  4. end
  5. def plain_server(*args, **kargs, &block)
  6. plain_serv *args, **kargs, &block
  7. end
  8. def analyze(*args)
  9. CryptCheck::Tls::Https.analyze *args
  10. end
  11. include_examples :analysis
  12. describe '#hsts?' do
  13. it 'has no hsts' do
  14. grades = server host: '127.0.0.1' do
  15. analyze '127.0.0.1', 5000
  16. end
  17. _, server = expect_grade grades, '127.0.0.1', '127.0.0.1', 5000, :ipv4
  18. expect(server.hsts?).to be false
  19. end
  20. it 'has hsts' do
  21. process = proc do |socket|
  22. socket.print [
  23. 'HTTP/1.1 200 OK',
  24. 'Strict-transport-security: max-age=31536000; includeSubdomains; preload',
  25. 'Content-Type: text/plain',
  26. 'Content-Length: 0',
  27. 'Connection: close'
  28. ].join "\r\n"
  29. end
  30. grades = server host: '127.0.0.1', process: process do
  31. analyze '127.0.0.1', 5000
  32. end
  33. _, server = expect_grade grades, '127.0.0.1', '127.0.0.1', 5000, :ipv4
  34. expect(server.hsts?).to be true
  35. end
  36. end
  37. describe '#hsts_long?' do
  38. it 'has no hsts' do
  39. grades = server host: '127.0.0.1' do
  40. analyze '127.0.0.1', 5000
  41. end
  42. _, server = expect_grade grades, '127.0.0.1', '127.0.0.1', 5000, :ipv4
  43. expect(server.hsts_long?).to be false
  44. end
  45. it 'has hsts but not long' do
  46. process = proc do |socket|
  47. socket.print [
  48. 'HTTP/1.1 200 OK',
  49. "Strict-transport-security: max-age=#{CryptCheck::Tls::Https::Server::LONG_HSTS-1}; includeSubdomains; preload",
  50. 'Content-Type: text/plain',
  51. 'Content-Length: 0',
  52. 'Connection: close'
  53. ].join "\r\n"
  54. end
  55. grades = server host: '127.0.0.1', process: process do
  56. analyze '127.0.0.1', 5000
  57. end
  58. _, server = expect_grade grades, '127.0.0.1', '127.0.0.1', 5000, :ipv4
  59. expect(server.hsts_long?).to be false
  60. end
  61. it 'has long hsts' do
  62. process = proc do |socket|
  63. socket.print [
  64. 'HTTP/1.1 200 OK',
  65. "Strict-transport-security: max-age=#{CryptCheck::Tls::Https::Server::LONG_HSTS}; includeSubdomains; preload",
  66. 'Content-Type: text/plain',
  67. 'Content-Length: 0',
  68. 'Connection: close'
  69. ].join "\r\n"
  70. end
  71. grades = server host: '127.0.0.1', process: process do
  72. analyze '127.0.0.1', 5000
  73. end
  74. _, server = expect_grade grades, '127.0.0.1', '127.0.0.1', 5000, :ipv4
  75. expect(server.hsts_long?).to be true
  76. end
  77. end
  78. end