All Files
(100.0%
covered at
2.02
hits/line)
9 files in total.
271 relevant lines.
271 lines covered and
0 lines missed
Libraries
(100.0%
covered at
0.0
hits/line)
0 files in total.
0.0 relevant lines.
0.0 lines covered and
0.0 lines missed
File |
% covered |
Lines |
Relevant Lines |
Lines covered |
Lines missed |
Avg. Hits / Line |
Spec
(100.0%
covered at
2.02
hits/line)
9 files in total.
271 relevant lines.
271 lines covered and
0 lines missed
-
1
require "spec_helper"
-
-
1
describe Diversion::Decode::Json do
-
-
1
include_context "json"
-
-
1
it "returns correct type for non-signed" do
-
1
expect(decode_json).to be_a Hash
-
end
-
-
1
it "returns correct type for signed" do
-
1
expect(decode_json_signed).to be_a Hash
-
end
-
-
1
it "raises when data format invalid" do
-
2
expect{client.decode("test-test-test")}.to raise_error(Diversion::Error::BadUrlDataFormat)
-
end
-
-
1
it "doesn't parse when passed bad data" do
-
1
expect(client.decode("test-test")[:parsed]).to be_false
-
end
-
-
1
it "parses when passed good data" do
-
1
expect(decode_json[:parsed]).to be_true
-
end
-
-
1
it "returns expected values when passed good unsigned data" do
-
1
hash = decode_json
-
1
expect(hash[:url]).to eq("http://test.com/test")
-
1
expect(hash[:signed]).to be_false
-
1
expect(hash[:key_presented]).to be_empty
-
1
expect(hash[:key_expected]).to be_empty
-
1
expect(hash[:key_verified]).to be_false
-
end
-
-
1
it "returns expected values when passed good signed data" do
-
1
hash = decode_json_signed
-
1
expect(hash[:url]).to eq("http://test.com/test")
-
1
expect(hash[:signed]).to be_true
-
1
expect(hash[:key_presented]).to eq(JSON_KEY)
-
1
expect(hash[:key_expected]).to eq(JSON_KEY)
-
1
expect(hash[:key_verified]).to be_true
-
end
-
-
1
it "returns expected values when passed badly signed data" do
-
1
hash = decode_json_bad_key
-
1
expect(hash[:url]).to eq("http://test.com/test")
-
1
expect(hash[:signed]).to be_true
-
1
expect(hash[:key_presented]).to eq(JSON_KEY_BAD)
-
1
expect(hash[:key_expected]).to eq(JSON_KEY)
-
1
expect(hash[:key_verified]).to be_false
-
end
-
-
1
it "decodes parameters as expected" do
-
1
enc = client.encode(HTML, {:b => 999})
-
1
data = enc.scan(/".*?\/.*?\/.*?\/(.*?)"/).first.first
-
1
result = client.decode(data)
-
1
expect(result[:test]).to eq("1234")
-
1
expect(result[:b]).to eq(999)
-
end
-
-
1
it "decodes parameters as expected when signed" do
-
1
enc = client_sign.encode(HTML, {:b => 999})
-
1
data = enc.scan(/".*?\/.*?\/.*?\/(.*?)"/).first.first
-
1
hash = client.decode(data)
-
1
expect(hash[:test]).to eq("1234")
-
1
expect(hash[:b]).to eq(999)
-
end
-
-
end
-
1
require "spec_helper"
-
-
1
describe Diversion::Decode::Params do
-
-
1
include_context "params"
-
-
1
it "returns correct type for non-signed" do
-
1
expect(decode_params).to be_a Hash
-
end
-
-
1
it "returns correct type for signed" do
-
1
expect(decode_params_signed).to be_a Hash
-
end
-
-
1
it "raises when data format invalid" do
-
2
expect{client.decode("badparam=badvalue")}.to raise_error(Diversion::Error::BadUrlDataFormat)
-
end
-
-
1
it "raises when data format invalid" do
-
2
expect{client.decode("rubbish")}.to raise_error(Diversion::Error::BadUrlDataFormat)
-
end
-
-
1
it "raises when missing url data parameter" do
-
2
expect{client.decode("d=#{CGI::escape('badparam=badvalue')}")}.to raise_error(Diversion::Error::BadUrlDataFormat)
-
end
-
-
1
it "raises when missing url data parameter empty" do
-
2
expect{client.decode("d=#{CGI::escape('url=')}")}.to raise_error(Diversion::Error::BadUrlDataFormat)
-
end
-
-
1
it "returns expected values when passed good unsigned data" do
-
1
hash = decode_params
-
1
expect(hash[:url]).to eq("http://test.com/test")
-
1
expect(hash[:signed]).to be_false
-
1
expect(hash[:key_presented]).to be_empty
-
1
expect(hash[:key_expected]).to be_empty
-
1
expect(hash[:key_verified]).to be_false
-
end
-
-
1
it "returns expected values when passed good signed data" do
-
1
hash = decode_params_signed
-
1
expect(hash[:url]).to eq("http://test.com/test")
-
1
expect(hash[:signed]).to be_true
-
1
expect(hash[:key_presented]).to eq(PARAMS_KEY)
-
1
expect(hash[:key_expected]).to eq(PARAMS_KEY)
-
1
expect(hash[:key_verified]).to be_true
-
end
-
-
1
it "returns expected values when passed badly signed data" do
-
1
hash = decode_params_bad_key
-
1
expect(hash[:url]).to eq("http://test.com/test")
-
1
expect(hash[:signed]).to be_true
-
1
expect(hash[:key_presented]).to eq(PARAMS_KEY_BAD)
-
1
expect(hash[:key_expected]).to eq(PARAMS_KEY)
-
1
expect(hash[:key_verified]).to be_false
-
end
-
-
1
it "decodes parameters as expected" do
-
1
enc = client.encode(HTML, {:b => 999})
-
1
data = enc.scan(/".*?\/.*?\/.*?\/(.*?)"/).first.first[1..-1]
-
1
result = client.decode(data)
-
1
expect(result[:test]).to eq("1234")
-
1
expect(result[:b]).to eq("999")
-
end
-
-
1
it "decodes parameters as expected when signed" do
-
1
enc = client_sign.encode(HTML, {:b => 999})
-
1
data = enc.scan(/".*?\/.*?\/.*?\/(.*?)"/).first.first[1..-1]
-
1
hash = client.decode(data)
-
1
expect(hash[:test]).to eq("1234")
-
1
expect(hash[:b]).to eq("999")
-
end
-
-
end
-
1
require "spec_helper"
-
-
1
describe Diversion::Decode do
-
-
# we use json encoding here but it doesn't matter as we're testing common functionality
-
1
include_context "json"
-
-
1
it "raise ArgumentError if data.length == 0" do
-
2
expect{client.decode("")}.to raise_error(ArgumentError)
-
end
-
-
end
-
1
require "spec_helper"
-
-
1
describe Diversion::Encode do
-
-
# we use json encoding here but it doesn't matter as we're testing common functionality
-
1
include_context "json"
-
-
1
it "ignores non-http uris" do
-
1
expect(encode_email).to include('mailto:jess@doesnotexist.domain')
-
end
-
-
1
it "converts http uris" do
-
1
expect(encode_email).to_not include('https://twitter.com/intent/tweet?in_reply_to=51113028241989632')
-
end
-
-
1
it "removes data attributes" do
-
1
expect(encode_email).to_not include('data-')
-
end
-
-
1
it "raises when signing key not set" do
-
1
client_sign.sign_key = nil
-
2
expect { encode_json_html_signed }.to raise_error(Diversion::Error::KeyMissingError)
-
end
-
-
1
it "raises when no uris defined" do
-
1
client.encode_uris = []
-
2
expect { encode_json_html_signed }.to raise_error(Diversion::Error::UriMissingError)
-
end
-
-
end
-
1
require "spec_helper"
-
-
1
describe Diversion::Encode::Json do
-
-
1
include_context "json"
-
-
1
it "returns correct type" do
-
1
expect(encode_email).to be_a String
-
end
-
-
1
it "uses correct path" do
-
1
expect(encode_json_html).to eq(html_json_encoded)
-
end
-
-
1
it "doesn't add port for 80" do
-
1
client.port = 80
-
1
expect(encode_json_html).to eq(html_json_encoded)
-
end
-
-
1
it "adds port number for non-80 port" do
-
1
client.port = 81
-
1
expect(encode_json_html).to eq(html_json_encoded({:port => 81}))
-
end
-
-
1
it "doesn't sign by default" do
-
1
expect(encode_json_html).to eq(html_json_encoded)
-
end
-
-
1
it "signs correctly" do
-
1
client_sign.sign_length = 32
-
1
expect(encode_json_html_signed).to eq(html_json_encoded({:sign_length => DEFAULT_SIGN_LEN}) )
-
end
-
-
1
it "observes sign_length" do
-
1
client_sign.sign_length = 2
-
1
expect(encode_json_html_signed).to eq(html_json_encoded({:sign_length => 2}) )
-
end
-
-
end
-
1
require "spec_helper"
-
-
1
describe Diversion::Encode::Params do
-
-
1
include_context "params"
-
-
1
it "returns correct type" do
-
1
expect(encode_email).to be_a String
-
end
-
-
1
it "uses correct path" do
-
1
expect(encode_params_html).to eq(html_params_encoded)
-
end
-
-
1
it "doesn't add port for 80" do
-
1
client.port = 80
-
1
expect(encode_params_html).to eq(html_params_encoded)
-
end
-
-
1
it "adds port number for non-80 port" do
-
1
client.port = 81
-
1
expect(encode_params_html).to eq(html_params_encoded({:port => 81}))
-
end
-
-
1
it "doesn't sign by default" do
-
1
expect(encode_params_html).to eq(html_params_encoded)
-
end
-
-
1
it "signs correctly" do
-
1
client_sign.sign_length = 32
-
1
expect(encode_params_html_signed).to eq(html_params_encoded({:sign_length => DEFAULT_SIGN_LEN}))
-
end
-
-
1
it "observes sign_length" do
-
1
client_sign.sign_length = 2
-
1
expect(encode_params_html_signed).to eq(html_params_encoded({:sign_length => 2}))
-
end
-
-
end
-
1
def use_json
-
23
{ :url_encoding => Diversion::Encode::Json, :url_decoding => Diversion::Decode::Json }
-
end
-
-
1
def use_params
-
19
{ :url_encoding => Diversion::Encode::Params, :url_decoding => Diversion::Decode::Params }
-
end
-
-
1
shared_context 'json' do
-
21
let(:client) { @client ||= Diversion::Client.new(use_json) }
-
12
let(:client_sign) { @client ||= Diversion::Client.new(use_json.merge({:sign_length => 32, :sign_key => SIGN_KEY})) }
-
8
let(:encode_email) { @email = client.encode(fixture('mail.html').read, {:a => 1}) }
-
8
let(:encode_json_html) { client.encode(HTML) }
-
8
let(:encode_json_html_signed) { client_sign.encode(HTML) }
-
7
let(:decode_json) { client.decode(JSON_ENCODED) }
-
6
let(:decode_json_signed) { client_sign.decode(JSON_ENCODED_SIGNED) }
-
5
let(:decode_json_bad_key) { client_sign.decode(JSON_ENCODED_SIGNED_KEY_BAD) }
-
end
-
-
1
shared_context 'params' do
-
15
let(:client) { Diversion::Client.new(use_params) }
-
8
let(:client_sign) { Diversion::Client.new(use_params.merge({:sign_length => 32, :sign_key => SIGN_KEY})) }
-
3
let(:encode_email) { @email = client.encode(fixture('mail.html').read, {:a => 1}) }
-
6
let(:encode_params_html) { client.encode(HTML) }
-
4
let(:encode_params_html_signed) { client_sign.encode(HTML) }
-
4
let(:decode_params) { client.decode(PARAMS_ENCODED) }
-
4
let(:decode_params_signed) { client_sign.decode(PARAMS_ENCODED_SIGNED) }
-
3
let(:decode_params_bad_key) { client_sign.decode(PARAMS_ENCODED_SIGNED_KEY_BAD) }
-
end
-
1
require "spec_helper"
-
-
1
describe "Test Url Encoding" do
-
-
1
it "can encode/decode URL successfully" do
-
1
attrs = { :test => 1234, :url => 'http://somewhere.over.rainbow'}
-
1
url = "d=#{CGI::escape(attrs.to_param)}&s=testkey"
-
1
parsed = CGI::parse(url)
-
#puts parsed
-
1
expect(parsed.length).to eq(2)
-
1
expect(parsed.has_key?('d')).to be_true
-
1
expect(parsed.has_key?('s')).to be_true
-
1
expect(parsed.has_key?('url')).to be_false
-
1
expect(parsed.has_key?('test')).to be_false
-
1
expect(parsed['s'].first).to eq("testkey")
-
1
data = CGI::parse(parsed['d'].first)
-
#puts data
-
1
expect(data['test'].first).to eq("1234")
-
1
expect(data['url'].first).to eq("http://somewhere.over.rainbow")
-
end
-
-
end