base64_spec.rb 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require 'spec_helper'
  2. describe 'base64' do
  3. it { is_expected.not_to eq(nil) }
  4. it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) }
  5. it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError) }
  6. it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{first argument must be one of}) }
  7. it { is_expected.to run.with_params('encode', ['two']).and_raise_error(Puppet::ParseError, %r{second argument must be a string}) }
  8. it { is_expected.to run.with_params('encode', 2).and_raise_error(Puppet::ParseError, %r{second argument must be a string}) }
  9. it { is_expected.to run.with_params('encode', 'thestring', 'three').and_raise_error(Puppet::ParseError, %r{third argument must be one of}) }
  10. it { is_expected.to run.with_params('decode', "dGhlc3RyaW5n\n", 'strict').and_raise_error(ArgumentError) }
  11. it { is_expected.to run.with_params('encode', 'thestring').and_return("dGhlc3RyaW5n\n") }
  12. it { is_expected.to run.with_params('decode', 'dGhlc3RyaW5n').and_return('thestring') }
  13. it { is_expected.to run.with_params('decode', "dGhlc3RyaW5n\n").and_return('thestring') }
  14. it { is_expected.to run.with_params('encode', 'thestring', 'default').and_return("dGhlc3RyaW5n\n") }
  15. it { is_expected.to run.with_params('decode', 'dGhlc3RyaW5n', 'default').and_return('thestring') }
  16. it { is_expected.to run.with_params('decode', "dGhlc3RyaW5n\n", 'default').and_return('thestring') }
  17. it { is_expected.to run.with_params('encode', 'thestring', 'strict').and_return('dGhlc3RyaW5n') }
  18. it { is_expected.to run.with_params('decode', 'dGhlc3RyaW5n', 'strict').and_return('thestring') }
  19. it {
  20. is_expected.to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines')
  21. .and_return("YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
  22. }
  23. it {
  24. is_expected.to run.with_params('decode', "YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0\nIGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5l\ncw==\n")
  25. .and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
  26. }
  27. it {
  28. is_expected.to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
  29. .and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
  30. }
  31. it {
  32. is_expected.to run.with_params('encode', 'a very long string that will cause the base64 encoder to produce output with multiple lines', 'strict')
  33. .and_return('YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==')
  34. }
  35. it {
  36. is_expected.to run.with_params('decode', 'YSB2ZXJ5IGxvbmcgc3RyaW5nIHRoYXQgd2lsbCBjYXVzZSB0aGUgYmFzZTY0IGVuY29kZXIgdG8gcHJvZHVjZSBvdXRwdXQgd2l0aCBtdWx0aXBsZSBsaW5lcw==', 'strict')
  37. .and_return('a very long string that will cause the base64 encoder to produce output with multiple lines')
  38. }
  39. it {
  40. is_expected.to run.with_params('encode', 'https://www.google.com.tw/?gws_rd=ssl#q=hello+world', 'urlsafe')
  41. .and_return('aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk')
  42. }
  43. it {
  44. is_expected.to run.with_params('decode', 'aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS50dy8_Z3dzX3JkPXNzbCNxPWhlbGxvK3dvcmxk', 'urlsafe')
  45. .and_return('https://www.google.com.tw/?gws_rd=ssl#q=hello+world')
  46. }
  47. it {
  48. is_expected.to run.with_params('encode', 'https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add', 'urlsafe')
  49. .and_return('aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=')
  50. }
  51. it {
  52. is_expected.to run.with_params('decode', 'aHR0cHM6Ly9naXRodWIuY29tL3B1cHBldGxhYnMvcHVwcGV0bGFicy1zdGRsaWIvcHVsbHM_dXRmOD0lRTIlOUMlOTMmcT1pcyUzQXByK2lzJTNBb3BlbitBZGQ=', 'urlsafe')
  53. .and_return('https://github.com/puppetlabs/puppetlabs-stdlib/pulls?utf8=%E2%9C%93&q=is%3Apr+is%3Aopen+Add')
  54. }
  55. end