Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

xmpp_spec.rb 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. describe CryptCheck::Tls::Xmpp do
  2. def server(*args, **kargs, &block)
  3. kargs[:plain_process] = proc do |socket|
  4. socket.gets
  5. socket.puts "<?xml version='1.0'?><stream:stream xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='localhost' id='' xml:lang='en' xmlns='jabber:server'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls><dialback xmlns='urn:xmpp:features:dialback'/></stream:features>"
  6. socket.gets
  7. socket.puts "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />"
  8. true
  9. end unless kargs.include? :plain_process
  10. starttls_serv *args, **kargs, &block
  11. end
  12. def plain_server(*args, **kargs, &block)
  13. kargs[:plain_process] = proc do |socket|
  14. socket.gets
  15. socket.puts "<?xml version='1.0'?><stream:stream xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='localhost' id='' xml:lang='en' xmlns='jabber:server'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls><dialback xmlns='urn:xmpp:features:dialback'/></stream:features>"
  16. socket.gets
  17. socket.puts "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />"
  18. false
  19. end unless kargs.include? :plain_process
  20. starttls_serv *args, **kargs, &block
  21. end
  22. def analyze(*args)
  23. CryptCheck::Tls::Xmpp.analyze *args, type: :s2s
  24. end
  25. include_examples :analysis do
  26. it 'return error on XMPP error' do
  27. plain_process = proc do |socket|
  28. socket.gets
  29. socket.puts "<?xml version='1.0'?><stream:stream xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='localhost' id='' xml:lang='en' xmlns='jabber:server'><stream:error><invalid-namespace xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>"
  30. false
  31. end
  32. grades = server host: '127.0.0.1', plain_process: plain_process do
  33. analyze '127.0.0.1', 5000
  34. end
  35. expect_grade_error grades, '127.0.0.1', '127.0.0.1', 5000,
  36. '<invalid-namespace xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>'
  37. end
  38. end
  39. describe '#required?' do
  40. it 'has TLS not required' do
  41. grades = server host: '127.0.0.1' do
  42. analyze '127.0.0.1', 5000
  43. end
  44. _, server = expect_grade grades, '127.0.0.1', '127.0.0.1', 5000, :ipv4
  45. expect(server.required?).to be false
  46. end
  47. it 'has TLS required' do
  48. plain_process = proc do |socket|
  49. socket.gets
  50. socket.puts "<?xml version='1.0'?><stream:stream xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='localhost' id='' xml:lang='en' xmlns='jabber:server'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls><dialback xmlns='urn:xmpp:features:dialback'/></stream:features>"
  51. socket.gets
  52. socket.puts "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />"
  53. true
  54. end
  55. grades = server host: '127.0.0.1', plain_process: plain_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.required?).to be true
  60. end
  61. end
  62. end