Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/postgres/postgres-pr/scram_sha_256_spec.rb
Views: 11784
require 'postgres/postgres-pr/scram_sha_256'12RSpec.describe Msf::Db::PostgresPR::ScramSha256 do3describe '#hi' do4[5{ str: "a", salt: "c", iteration_count: 1, expected: "\xF5*3|\x9ALKB\xD1\x8D\x96d\xC1\x1D\v\xAEY^\xA8\xBB?o\x90\xE0\bE\xD5\xE1!\xA9={".b },6{ str: "a", salt: "c", iteration_count: 4096, expected: ")\xA4\x1E\xF6$Vn\x17~w\xFAA\xB4\x8C\xEFY\x83\x82}, 2\xCB\x02\x19Q\xB7\xADOR\xD9\xDC".b },7{ str: "pencil", salt: "\x00" * 16, iteration_count: 4096, expected: "\xB1q\x84\xD9\x8E\x0EG\xB2\"\xBD~\xB3-\xDABV?x\xC8'\xB7\xC8r\x9FJhG\xDAB%\xA0~".b },8{ str: "pencil", salt: "\x8C\xDDM\x0E\xDBa\xD5\xE4?\x8C\xF3V\xC9\xC9\x94V", iteration_count: 4096, expected: "\xB1?1\xF3\x86\xF5\"\x0F\xCB\xE3=\xE1\xFF(\xF0\x9BODB\xDD\xEF8\xCC\n\x16\x83\x1A&C\xA2\x86F".b },9].each do |test|10it "returns the expected value for the test #{test}" do11expect(subject.hi(test[:str], test[:salt], test[:iteration_count])).to eq(test[:expected])12end13end14end1516describe '#gs2_header' do17context 'when channel binding is false' do18it 'returns a header without any channel bindings' do19expect(subject.gs2_header(channel_binding: false)).to eq 'n,,'20end21end2223context 'when channel binding is true' do24it 'returns a header without any channel bindings' do25expect { subject.gs2_header(channel_binding: true) }.to raise_error NotImplementedError, 'Channel binding not implemented'26end27end28end2930describe '#normalize' do31[32#33# Tests from spec https://datatracker.ietf.org/doc/html/rfc4013#section-334#35{ str: "I\u00ADX", expected: "IX" },36{ str: "user", expected: "user" },37{ str: "USER", expected: "USER" },38{ str: "\u00AA", expected: "a" },39{ str: "\u2168", expected: "IX" },40{ str: "\u0007", error: /ASCII control characters/ },41{ str: "\u0627\u0031", error: /must start.*end with RandAL/ },4243#44# Tests from saslprep implementation in Ruby gem https://github.com/ruby/net-imap/blob/92dabbb8959a7a1e02990968ee6a5f4f73dded17/test/net/imap/test_saslprep.rb#L37-L6945#46# some more prohibited codepoints47{ str: "\x7f", error: /ASCII control character/i },48{ str: "\ufff9", error: /Non-ASCII control character/i },49{ str: "\ue000", error: /private use.*C.3/i },50{ str: "\u{f0000}", error: /private use.*C.3/i },51{ str: "\u{100000}", error: /private use.*C.3/i },52{ str: "\ufffe", error: /Non-character code point.*C.4/i },53{ str: "\xed\xa0\x80", error: /invalid byte seq\w+ in UTF-8/i },54{ str: "\ufffd", error: /inapprop.* plain text.*C.6/i },55{ str: "\u2FFb", error: /inapprop.* canonical rep.*C.7/i },56{ str: "\u202c", error: /change display.*deprecate.*C.8/i },57{ str: "\u{e0001}", error: /tagging character/i },58# some more invalid bidirectional characters59{ str: "\u0627abc\u0627", error: /must not contain.* Lcat/i },60{ str: "\u0627123", error: /must start.*end with RandAL/i },6162#63# Arbitrary tests:64#65{ str: "abc".force_encoding("ASCII"), expected: "abc".force_encoding("UTF-8") },66{ str: 'abcABC123!@£$%^&*()_+=[];l/.,?><|":]}{P+_) hello world', expected: 'abcABC123!@£$%^&*()_+=[];l/.,?><|":]}{P+_) hello world' }67].each do |test|68it "returns the expected value for the test #{test}", skip: test[:skip] do69if test[:error]70expected_clazz = Msf::Db::PostgresPR::ScramSha256::NormalizeError71expected_message = test[:error]72expect { subject.normalize(test[:str]) }.to raise_error expected_clazz, expected_message73else74expect(subject.normalize(test[:str])).to eq(test[:expected])75end76end77end78end7980describe '#hmac' do81[82{ key: "\x00\x01\x02\x03", message: "hello world", expected: "abc".b }83].each do |test|84it "returns the expected value for the test #{test}" do85expect(subject.hmac(test[:key], test[:message])).to eq("e\xA7\xB1r\xA9^9,\x90\x9Aey>FD\xF8\xCC\xD1\xDDH\xBB\x90\xDDU\xE5\x04\x05\xFA\xEC\xFC\x8Ew".b)86end87end88end89end909192