Permalink
Browse files

Don't try to parse the receipt.

I was under the assumption that a receipt was JSON data and could be parsed
for inspection. Instead we now treat it as a unparsable blob.
  • Loading branch information...
1 parent b1c9bf0 commit f0148e0ff872ea3df6373abd0f7ec9fd44d740ef @Manfred Manfred committed Sep 18, 2012
View
@@ -2,7 +2,8 @@
module Oja
class Receipt
- attr_accessor :data, :filename
+ attr_accessor :filename
+ attr_writer :data
def initialize(attributes)
attributes.each do |attribute, value|
@@ -22,12 +23,12 @@ def read
File.read(filename)
end
- def json_data
- data ? JSON.dump(data) : read
+ def data
+ @data ||= read
end
def receipt_data
- Base64.encode64(json_data)
+ Base64.encode64(data)
end
def to_json
@@ -45,11 +46,5 @@ def verify
end
end
end
-
- private
-
- def data_or_read
- data || File.read(filename)
- end
end
end
@@ -0,0 +1,7 @@
+{
+ "signature" = "AjjGmGH321nvAhCYqMOEEJb9D0GJwQaQZz/FuH40/GIdBYq6bYzWgg7K565RNoFVZnrCfl2lNynGUoMzZZNDGlyA70n+EUbGeZpDIWFCNn/kTpVnfwY5QYaRvXdaOIIroKoUAS48kQPELFR/olSEGvVdkIKxYb5CXFQ879WHMfuLAAADVzCCA1MwggI7oAMCAQICCGUUkU3ZWAS1MA0GCSqGSIb3DQEBBQUAMH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQKDApBcHBsZSBJbmMuMSYwJAYDVQQLDB1BcHBsZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEzMDEGA1UEAwwqQXBwbGUgaVR1bmVzIFN0b3JlIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA5MDYxNTIyMDU1NloXDTE0MDYxNDIyMDU1NlowZDEjMCEGA1UEAwwaUHVyY2hhc2VSZWNlaXB0Q2VydGlmaWNhdGUxGzAZBgNVBAsMEkFwcGxlIGlUdW5lcyBTdG9yZTETMBEGA1UECgwKQXBwbGUgSW5jLjELMAkGA1UEBhMCVVMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMrR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xIjsKCSJvcmlnaW5hbC1wdXJjaGFzZS1kYXRlLW1zIiA9ICIxMzQ3NTMxMTgyMTMwIjsKCSJwcm9kdWN0LWlkIiA9ICJkYXkiOwoJIml0ZW0taWQiID0gIjU1OTc0NzkzNiI7CgkiYmlkIiA9ICJubC5ucmMueHMiOwoJInB1cmNoYXNlLWRhdGUtbXMiID0gIjEzNDc1MzExODIxMzAiOwoJInB1cmNoYXNlLWRhdGUiID0gIjIwMTItMDktMTMgMTA6MTM6MDIgRXRjL0dNVCI7CgkicHVyY2hhc2UtZGF0ZS1wc3QiID0gIjIwMTItMDktMTMgMDM6MTM6MDIgQW1lcmljYS9Mb3NfQW5nZWxlcyI7Cgkib3JpZ2luYWwtcHVyY2hhc2UtZGF0ZSIgPSAiMjAxMi0wOS0xMyAxMDoxMzowMiBFdGMvR01UIjsKfQ==";
+ "environment" = "Sandbox";
+ "pod" = "100";
+ "signing-status" = "0";
+}
View
@@ -3,20 +3,20 @@
describe Oja do
it "verifies an active receipt from disk" do
- response = Oja.verify_filename(receipt_filename('auto_renewable'))
+ response = Oja.verify_filename(receipt_filename('receipt'))
# The default for the mock response is success
response.should.be.active
end
it "verifies an inactive receipt from disk" do
Oja::Mock.responses << [200, { status: Oja::Response.status_code(:inactive) }]
- response = Oja.verify_filename(receipt_filename('auto_renewable'))
+ response = Oja.verify_filename(receipt_filename('receipt'))
response.should.be.inactive
end
it "does not return a response when the HTTP request fails" do
Oja::Mock.responses << [500, {}]
- response = Oja.verify_filename(receipt_filename('auto_renewable'))
+ response = Oja.verify_filename(receipt_filename('receipt'))
response.should == nil
end
end
View
@@ -6,7 +6,7 @@
class Peck::Context
def receipt_filename(name)
- filename = File.expand_path("../fixtures/receipts/#{name}.json", __FILE__)
+ filename = File.expand_path("../fixtures/receipts/#{name}.txt", __FILE__)
if File.exist?(filename)
filename
else
@@ -15,10 +15,6 @@ def receipt_filename(name)
end
def receipt_data(name)
- JSON.parse(File.read(receipt_filename(name)))
- end
-
- def receipt_as_json(name)
- JSON.dump(receipt_data(name))
+ File.read(receipt_filename(name))
end
end
View
@@ -2,12 +2,12 @@
describe Oja::Receipt do
it "loads a receipt from disk" do
- receipt = Oja::Receipt.new(:filename => receipt_filename('auto_renewable'))
- JSON.parse(receipt.json_data).should == receipt_data('auto_renewable')
+ receipt = Oja::Receipt.new(:filename => receipt_filename('receipt'))
+ receipt.data.should == receipt_data('receipt')
end
it "accepts data for a receipt" do
- receipt = Oja::Receipt.new(:data => receipt_data('auto_renewable'))
- JSON.parse(receipt.json_data).should == receipt_data('auto_renewable')
+ receipt = Oja::Receipt.new(:data => receipt_data('receipt'))
+ receipt.data.should == receipt_data('receipt')
end
end

0 comments on commit f0148e0

Please sign in to comment.