From fb57d555c68d59119cd8f4062f2a9215546156f4 Mon Sep 17 00:00:00 2001 From: Chase Southard Date: Sat, 20 Jul 2019 14:33:15 -0400 Subject: [PATCH] update client to version 2. can't get 'previous' to work --- .travis.yml | 6 +- lib/nist_randomness_beacon/client.rb | 36 ++++++++---- nist_randomness_beacon.gemspec | 15 ++--- spec/cassettes/current_beacon_v2.yml | 65 +++++++++++++++++++++ spec/cassettes/last_beacon_v2.yml | 65 +++++++++++++++++++++ spec/cassettes/next_beacon_v2.yml | 65 +++++++++++++++++++++ spec/cassettes/previous_beacon_v2.yml | 39 +++++++++++++ spec/cassettes/pulse_in_chain_beacon_v2.yml | 65 +++++++++++++++++++++ spec/cassettes/start_chain_beacon_v2.yml | 65 +++++++++++++++++++++ spec/client_spec.rb | 39 ++++++++++--- 10 files changed, 431 insertions(+), 29 deletions(-) create mode 100644 spec/cassettes/current_beacon_v2.yml create mode 100644 spec/cassettes/last_beacon_v2.yml create mode 100644 spec/cassettes/next_beacon_v2.yml create mode 100644 spec/cassettes/previous_beacon_v2.yml create mode 100644 spec/cassettes/pulse_in_chain_beacon_v2.yml create mode 100644 spec/cassettes/start_chain_beacon_v2.yml diff --git a/.travis.yml b/.travis.yml index 449e59b..bc041b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 2.5.0 - - 2.4.0 - - 2.3.0 + - 2.6.2 + - 2.5.5 + - 2.4.5 script: bundle exec rspec spec diff --git a/lib/nist_randomness_beacon/client.rb b/lib/nist_randomness_beacon/client.rb index e527852..fb706cb 100644 --- a/lib/nist_randomness_beacon/client.rb +++ b/lib/nist_randomness_beacon/client.rb @@ -3,8 +3,11 @@ module NISTRandomnessBeacon # Client to the NIST Randomness Beacon API + # Certificate + # https://beacon.nist.gov/beacon/2.0/certificate/ + # class Client - DEFAULT_URI = 'https://beacon.nist.gov/beacon/1.0/pulse'.freeze + DEFAULT_URI = 'https://beacon.nist.gov/beacon/2.0'.freeze include HTTParty attr_reader :timestamp, :uri @@ -15,42 +18,51 @@ def initialize(time=nil, uri=DEFAULT_URI) end # Returns the Current Record (or next closest AFTER the timestamp) - # https:////beacon/1.0/pulse/ + # https:///pulse/time/ # def current - response = self.class.get("#@uri/#@timestamp") + response = self.class.get("#@uri/pulse/time/#@timestamp") create_new_record(response) end # Returns the Previous Record - # https:////beacon/1.0/pulse/previous/ + # https:///pulse/time/previous/ # def previous - response = self.class.get("#@uri/previous/#@timestamp") + response = self.class.get("#@uri/pulse/time/previous/#@timestamp") create_new_record(response) end # Returns the Next Record - # https:////beacon/1.0/pulse/next/ + # https:///pulse/time/next/ # def next - response = self.class.get("#@uri/next/#@timestamp") + response = self.class.get("#@uri/pulse/time/next/#@timestamp") create_new_record(response) end # Returns the Last Record - # https:////beacon/1.0/pulse/last + # https:///pulse/last + # https:///beacon/2.0/chain/last/pulse/last # def last - response = self.class.get("#@uri/last") + response = self.class.get("#@uri/pulse/last") create_new_record(response) end # Returns the Start Chain Record - # https:////beacon/1.0/pulse/start-chain/ + # https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1 # - def start_chain - response = self.class.get("#@uri/start-chain/#@timestamp") + def start_chain() + response = self.class.get("#@uri/chain/1/pulse/1") + create_new_record(response) + end + + # Returns a Specific Pulse in a Specific Chain + # required arguments: a chain_index and a pulse_index both integers + # + def pulse_in_chain(chain_index:1, pulse_index:1) + response = self.class.get("#@uri/chain/#{chain_index}/pulse/#{pulse_index}") create_new_record(response) end diff --git a/nist_randomness_beacon.gemspec b/nist_randomness_beacon.gemspec index df9fb89..dfe5b37 100644 --- a/nist_randomness_beacon.gemspec +++ b/nist_randomness_beacon.gemspec @@ -17,18 +17,19 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.required_ruby_version = ['>= 2.3.0', '<= 2.5.0'] + spec.required_ruby_version = ['>= 2.4.0'] spec.add_development_dependency 'bundler', '~> 1.12' spec.add_development_dependency 'rake', '~> 12' spec.add_development_dependency 'awesome_print', '~> 1.7' spec.add_development_dependency 'yard', '~> 0.9.12' - spec.add_development_dependency 'rspec', '~> 3.5' + spec.add_development_dependency 'rspec', '~> 3.8' spec.add_development_dependency 'vcr', '~> 4.0' - spec.add_development_dependency 'webmock', '~> 3.3' - spec.add_development_dependency 'simplecov', '~> 0.12' - spec.add_development_dependency 'timecop', '~> 0.8' + spec.add_development_dependency 'webmock', '~> 3.5' + spec.add_development_dependency 'simplecov', '~> 0.16' + spec.add_development_dependency 'timecop', '~> 0.9' + spec.add_development_dependency 'irb' - spec.add_dependency 'httparty', '~> 0.15' - spec.add_dependency 'json', '~> 2.1' + spec.add_dependency 'httparty', '~> 0.16' + spec.add_dependency 'json', '~> 2.2' end diff --git a/spec/cassettes/current_beacon_v2.yml b/spec/cassettes/current_beacon_v2.yml new file mode 100644 index 0000000..0a3b6e0 --- /dev/null +++ b/spec/cassettes/current_beacon_v2.yml @@ -0,0 +1,65 @@ +--- +http_interactions: +- request: + method: get + uri: https://beacon.nist.gov/beacon/2.0/pulse/time/1554076800 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Cache-Control: + - no-cache, no-store, must-revalidate + Pragma: + - no-cache + Content-Type: + - application/json;charset=ISO-8859-1 + Expires: + - Thu, 01 Jan 1970 00:00:00 GMT + Server: + - Microsoft-IIS/8.5 + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + Date: + - Sat, 06 Apr 2019 14:42:39 GMT + Content-Length: + - '3359' + Strict-Transport-Security: + - max-age=31536000 + body: + encoding: UTF-8 + string: "{\r\n \"pulse\" : {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1\",\r\n + \ \"version\" : \"Version 2.0\",\r\n \"cipherSuite\" : 0,\r\n \"period\" + : 60000,\r\n \"certificateId\" : \"5501e3d72bc42f3b96e16de4dcadcb16768e109662bd16d667d5fd9aee585af31bbdc5dd4f53592276064b53dddd76c8f3604b2a41db6e09f78f82bb5d6569e7\",\r\n + \ \"chainIndex\" : 1,\r\n \"pulseIndex\" : 1,\r\n \"timeStamp\" : + \"2018-07-23T19:26:00.000Z\",\r\n \"localRandomValue\" : \"88C3BF231794D4D6654924EF771268AF1DA9C2D6A3EA62A79C42D6399CD9DE811C5C32CA71DE2EC867510A8CE44BE6D8694488BE530C02EEB602D8703A4D294F\",\r\n + \ \"external\" : {\r\n \"sourceId\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\r\n + \ \"statusCode\" : 0,\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ },\r\n \"listValues\" : [ {\r\n \"uri\" : null,\r\n \"type\" + : \"previous\",\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"hour\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"day\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"month\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"year\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ } ],\r\n \"precommitmentValue\" : \"6462C73A8D4913910C5AAA748EA82CD67EB4B73D2B3025121AA61354916CA65B9D25FD5FBECE2583E7C5EB172ECF2740472935A7A9013E6E7C84A9EBD6EFFA15\",\r\n + \ \"statusCode\" : 1,\r\n \"signatureValue\" : \"8FD04C3CB2631064C7917C98B606870D6A38C7CFD05CB589EB5F139471F07C8D553B997B583EC14648A1ECACDF0C0ED5E7C8F888E7F1DAF8D34E697B8A64A969DB92DBC8D49A4085AFA6CA068667677E6442F6E368458DE7E32490BD6C80F79276A1EBBD602B8379936758444214A3B8B5C3BF70A21CF4FD468B6C69717CC779CFA2D195ADB9F95139BB334E441D0633A18B7475FAEF4CDDF0F1E04FC84B1497EFE544B2F16F6BDD533E6DA444517FBB4A6C016845CF3367E296097B469A3AE6A19C30669DE37BCA1984C5410E631FFEB6DA1CF12654C98B5062C681D49594682938DF1C0E76A08B8F1896FDAB79A2AF4B8E12BD1127E4C8C046E7CA5F02359342114DCC7A9178937865B004BA86B2995045AA8F5505D4824C9855218F44AE83A99DE091DE619E1D6CA9E8A0C7E3E1ACBD3BC1E6354087EA5306328541D77B9E68364EA9FA747C3794F1B90A77350FE5A7DE0B6907339D2C9A3C57A07AECD70EC71CD5371AEE203934A472E5A7FFCB31B01EFF52374D5A7BFA55E8722843ADBBD63183BEE5565C01F51DB47069DA5007D1CF76FDA9070EAF4A12929A66190FC594377D60044F4E1809BD297CB540A90FFEE22F14F8C2754A7F256A5CA07AB451366102ECC7DFF8642CAEE1AFCF0147ECA24C79E9163B6E9FB262D179690F2460F269C3B209FE67737A60DB98B807E1E3147F3A8BBB482BE4BA93372508AD837A\",\r\n + \ \"outputValue\" : \"7665F054F21B50DF62CD3E50AF8EB783E30D271B091DE051212D301E0E3D17FFCF0367DB41CFFD3C51E88BDE0B0621F49EB03435BC373D5D49480941A8B3547E\"\r\n + \ }\r\n}" + http_version: + recorded_at: Mon, 01 Apr 2019 00:00:00 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/last_beacon_v2.yml b/spec/cassettes/last_beacon_v2.yml new file mode 100644 index 0000000..e1b58c5 --- /dev/null +++ b/spec/cassettes/last_beacon_v2.yml @@ -0,0 +1,65 @@ +--- +http_interactions: +- request: + method: get + uri: https://beacon.nist.gov/beacon/2.0/pulse/last + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Cache-Control: + - no-cache, no-store, must-revalidate + Pragma: + - no-cache + Content-Type: + - application/json;charset=ISO-8859-1 + Expires: + - Thu, 01 Jan 1970 00:00:00 GMT + Server: + - Microsoft-IIS/8.5 + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + Date: + - Sat, 06 Apr 2019 14:42:39 GMT + Content-Length: + - '3634' + Strict-Transport-Security: + - max-age=31536000 + body: + encoding: UTF-8 + string: "{\r\n \"pulse\" : {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/318328\",\r\n + \ \"version\" : \"Version 2.0\",\r\n \"cipherSuite\" : 0,\r\n \"period\" + : 60000,\r\n \"certificateId\" : \"5501e3d72bc42f3b96e16de4dcadcb16768e109662bd16d667d5fd9aee585af31bbdc5dd4f53592276064b53dddd76c8f3604b2a41db6e09f78f82bb5d6569e7\",\r\n + \ \"chainIndex\" : 1,\r\n \"pulseIndex\" : 318328,\r\n \"timeStamp\" + : \"2019-04-06T14:42:00.000Z\",\r\n \"localRandomValue\" : \"4558C917E88DCFFF9002C8D5F1572DA92F8E1A5032B1F503CE12787A9C44142FF7EA9386B0390631FA208421A3ECB78A03C121B5EF7010FEDECD435C79375F0B\",\r\n + \ \"external\" : {\r\n \"sourceId\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\r\n + \ \"statusCode\" : 0,\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ },\r\n \"listValues\" : [ {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/318327\",\r\n + \ \"type\" : \"previous\",\r\n \"value\" : \"B5AB76223CF165F41FD6FB4F59C58E0DEA616BB304FA73FDFF3176C9099A0F3138C67F3928FFC05ED3083C4BED80BB048269A6276EE072A09E87A82375649CA7\"\r\n + \ }, {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/318286\",\r\n + \ \"type\" : \"hour\",\r\n \"value\" : \"45DA224DAF929522C7ED8E3C78ED6A2F41EC0FFA0A316EA4CD87E5A014CF627C4F4E23C7D924A46CF7B1F3BB751239504D928B06E0A03FC1D54FED413D665E36\"\r\n + \ }, {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/317446\",\r\n + \ \"type\" : \"day\",\r\n \"value\" : \"805446C3446088E1357217E0B5D6321AB4B6CCBBD5604AB26857599B0EE356A30156D07BEC084F837F5523C4F921A541D20F35F5F21B89E0BCE7CF980CCD35ED\"\r\n + \ }, {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/310254\",\r\n + \ \"type\" : \"month\",\r\n \"value\" : \"E46CAE845BBE03E8E9A010048B77057295804F6FB8B2449C9DDF25A94827E253701190504BC7E39D4D51C83EBBDF0AC84ABBFBE6CE0D4670109CBB7B410B8B16\"\r\n + \ }, {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/220395\",\r\n + \ \"type\" : \"year\",\r\n \"value\" : \"04B73AFE1FA62CF42BF79FC9153329C671B983FC8685BC1946AF576D20BA08A65A402991EDC372FABC46AAB58FD41493022800EEA7107BC381B2A7D23D7030C3\"\r\n + \ } ],\r\n \"precommitmentValue\" : \"ECC3D9774F6C6933EA5E365D18E0B95F49BC190DDAD5AF6A4C5F3177AB639F61617E9016F53CDFDAAF5CBD4F7087531E4FD820844AA724E81C7A1E4145A2233F\",\r\n + \ \"statusCode\" : 0,\r\n \"signatureValue\" : \"D267321CDF83339FB468ABB924199B7A532F80C033EF5AF1F61E32CC1BD3CAEC89F2BB1F65EBE2DB507478BEC20F9C7A21E2443E1E2226AAF00BAAA44ACA5E0BFF5334E6D6BF55CD5AC09AD5597CF4393794C966BDC611673EE1B98816338CC751D29032B345937B99789EC2BB738BEDC31311965AC2C5B147CB513AA2F011A138DA95C5BEB59996785E04BFE1DBAB72CE5F6FB85878AF9127D1A4FEA710A18902BD45C1744744668A57A58B1B98373072D995BCDA94F9450A97B8474FA3EC8BE5A570944E1D3CDDCAF95D1875D9FB20E9DA53CBB2395F934BB22B958F95D5E329138C67A99A4B51A562A74B44B4B1BDF0DCFB876118CC17DBD0789CB44609ED577DA1B42E5699186BF1833EDE64658BE93AEBE2CBB25E8BDCE19AF87A5A2C1EFC020CC54CB17551537C2EDA039E8A35C037114178B7F055F7441FF7761448979C2B8F35D01928BCD6B8F52A2FD925F248A9BD9EF91F8D1CC5F1E501BFF7405644F3282B48B4C367BA783DE9017680D81179C649E0774BDFD483846365879C4C148407C8344D341388C5B2CBBB5FE84864690878608D88A27BE1AAC4F45A9A9045034B2D62B8FD6405CBD321C40CE705EE6C2F8409727646203967BAEA1B2AA30E4DEA585E44A916177819A26D136A2332B91FB7126642702A78F9693FF09BA1A1E27E120262A983DCD9C7D5F26EC1BD9B6A7FB7A8986195510DE063B8EF8CA5\",\r\n + \ \"outputValue\" : \"3E48610FACBA18F3E57404B65868256917DDE6895661DDCC1A67E675DF4901F10AC91E90060387B5686ADF448BED1273F79BD48BA36171B3BF1145BF4E4EFB52\"\r\n + \ }\r\n}" + http_version: + recorded_at: Mon, 01 Apr 2019 00:00:00 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/next_beacon_v2.yml b/spec/cassettes/next_beacon_v2.yml new file mode 100644 index 0000000..ba78702 --- /dev/null +++ b/spec/cassettes/next_beacon_v2.yml @@ -0,0 +1,65 @@ +--- +http_interactions: +- request: + method: get + uri: https://beacon.nist.gov/beacon/2.0/pulse/time/next/1554076800 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Cache-Control: + - no-cache, no-store, must-revalidate + Pragma: + - no-cache + Content-Type: + - application/json;charset=ISO-8859-1 + Expires: + - Thu, 01 Jan 1970 00:00:00 GMT + Server: + - Microsoft-IIS/8.5 + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + Date: + - Sat, 06 Apr 2019 14:42:39 GMT + Content-Length: + - '3359' + Strict-Transport-Security: + - max-age=31536000 + body: + encoding: UTF-8 + string: "{\r\n \"pulse\" : {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1\",\r\n + \ \"version\" : \"Version 2.0\",\r\n \"cipherSuite\" : 0,\r\n \"period\" + : 60000,\r\n \"certificateId\" : \"5501e3d72bc42f3b96e16de4dcadcb16768e109662bd16d667d5fd9aee585af31bbdc5dd4f53592276064b53dddd76c8f3604b2a41db6e09f78f82bb5d6569e7\",\r\n + \ \"chainIndex\" : 1,\r\n \"pulseIndex\" : 1,\r\n \"timeStamp\" : + \"2018-07-23T19:26:00.000Z\",\r\n \"localRandomValue\" : \"88C3BF231794D4D6654924EF771268AF1DA9C2D6A3EA62A79C42D6399CD9DE811C5C32CA71DE2EC867510A8CE44BE6D8694488BE530C02EEB602D8703A4D294F\",\r\n + \ \"external\" : {\r\n \"sourceId\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\r\n + \ \"statusCode\" : 0,\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ },\r\n \"listValues\" : [ {\r\n \"uri\" : null,\r\n \"type\" + : \"previous\",\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"hour\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"day\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"month\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"year\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ } ],\r\n \"precommitmentValue\" : \"6462C73A8D4913910C5AAA748EA82CD67EB4B73D2B3025121AA61354916CA65B9D25FD5FBECE2583E7C5EB172ECF2740472935A7A9013E6E7C84A9EBD6EFFA15\",\r\n + \ \"statusCode\" : 1,\r\n \"signatureValue\" : \"8FD04C3CB2631064C7917C98B606870D6A38C7CFD05CB589EB5F139471F07C8D553B997B583EC14648A1ECACDF0C0ED5E7C8F888E7F1DAF8D34E697B8A64A969DB92DBC8D49A4085AFA6CA068667677E6442F6E368458DE7E32490BD6C80F79276A1EBBD602B8379936758444214A3B8B5C3BF70A21CF4FD468B6C69717CC779CFA2D195ADB9F95139BB334E441D0633A18B7475FAEF4CDDF0F1E04FC84B1497EFE544B2F16F6BDD533E6DA444517FBB4A6C016845CF3367E296097B469A3AE6A19C30669DE37BCA1984C5410E631FFEB6DA1CF12654C98B5062C681D49594682938DF1C0E76A08B8F1896FDAB79A2AF4B8E12BD1127E4C8C046E7CA5F02359342114DCC7A9178937865B004BA86B2995045AA8F5505D4824C9855218F44AE83A99DE091DE619E1D6CA9E8A0C7E3E1ACBD3BC1E6354087EA5306328541D77B9E68364EA9FA747C3794F1B90A77350FE5A7DE0B6907339D2C9A3C57A07AECD70EC71CD5371AEE203934A472E5A7FFCB31B01EFF52374D5A7BFA55E8722843ADBBD63183BEE5565C01F51DB47069DA5007D1CF76FDA9070EAF4A12929A66190FC594377D60044F4E1809BD297CB540A90FFEE22F14F8C2754A7F256A5CA07AB451366102ECC7DFF8642CAEE1AFCF0147ECA24C79E9163B6E9FB262D179690F2460F269C3B209FE67737A60DB98B807E1E3147F3A8BBB482BE4BA93372508AD837A\",\r\n + \ \"outputValue\" : \"7665F054F21B50DF62CD3E50AF8EB783E30D271B091DE051212D301E0E3D17FFCF0367DB41CFFD3C51E88BDE0B0621F49EB03435BC373D5D49480941A8B3547E\"\r\n + \ }\r\n}" + http_version: + recorded_at: Mon, 01 Apr 2019 00:00:00 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/previous_beacon_v2.yml b/spec/cassettes/previous_beacon_v2.yml new file mode 100644 index 0000000..dc3ab87 --- /dev/null +++ b/spec/cassettes/previous_beacon_v2.yml @@ -0,0 +1,39 @@ +--- +http_interactions: +- request: + method: get + uri: https://beacon.nist.gov/beacon/2.0/pulse/time/previous/1554076800 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 404 + message: Not Found + headers: + Content-Type: + - text/html;charset=ISO-8859-1 + Server: + - Microsoft-IIS/8.5 + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + Date: + - Sat, 20 Jul 2019 18:06:42 GMT + Content-Length: + - '20' + Strict-Transport-Security: + - max-age=31536000 + body: + encoding: UTF-8 + string: Pulse Not Available. + http_version: + recorded_at: Mon, 01 Apr 2019 00:00:00 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/pulse_in_chain_beacon_v2.yml b/spec/cassettes/pulse_in_chain_beacon_v2.yml new file mode 100644 index 0000000..fbcdc9b --- /dev/null +++ b/spec/cassettes/pulse_in_chain_beacon_v2.yml @@ -0,0 +1,65 @@ +--- +http_interactions: +- request: + method: get + uri: https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Cache-Control: + - no-cache, no-store, must-revalidate + Pragma: + - no-cache + Content-Type: + - application/json;charset=ISO-8859-1 + Expires: + - Thu, 01 Jan 1970 00:00:00 GMT + Server: + - Microsoft-IIS/8.5 + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + Date: + - Sat, 20 Jul 2019 18:03:23 GMT + Content-Length: + - '3359' + Strict-Transport-Security: + - max-age=31536000 + body: + encoding: UTF-8 + string: "{\r\n \"pulse\" : {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1\",\r\n + \ \"version\" : \"Version 2.0\",\r\n \"cipherSuite\" : 0,\r\n \"period\" + : 60000,\r\n \"certificateId\" : \"5501e3d72bc42f3b96e16de4dcadcb16768e109662bd16d667d5fd9aee585af31bbdc5dd4f53592276064b53dddd76c8f3604b2a41db6e09f78f82bb5d6569e7\",\r\n + \ \"chainIndex\" : 1,\r\n \"pulseIndex\" : 1,\r\n \"timeStamp\" : + \"2018-07-23T19:26:00.000Z\",\r\n \"localRandomValue\" : \"88C3BF231794D4D6654924EF771268AF1DA9C2D6A3EA62A79C42D6399CD9DE811C5C32CA71DE2EC867510A8CE44BE6D8694488BE530C02EEB602D8703A4D294F\",\r\n + \ \"external\" : {\r\n \"sourceId\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\r\n + \ \"statusCode\" : 0,\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ },\r\n \"listValues\" : [ {\r\n \"uri\" : null,\r\n \"type\" + : \"previous\",\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"hour\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"day\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"month\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"year\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ } ],\r\n \"precommitmentValue\" : \"6462C73A8D4913910C5AAA748EA82CD67EB4B73D2B3025121AA61354916CA65B9D25FD5FBECE2583E7C5EB172ECF2740472935A7A9013E6E7C84A9EBD6EFFA15\",\r\n + \ \"statusCode\" : 1,\r\n \"signatureValue\" : \"8FD04C3CB2631064C7917C98B606870D6A38C7CFD05CB589EB5F139471F07C8D553B997B583EC14648A1ECACDF0C0ED5E7C8F888E7F1DAF8D34E697B8A64A969DB92DBC8D49A4085AFA6CA068667677E6442F6E368458DE7E32490BD6C80F79276A1EBBD602B8379936758444214A3B8B5C3BF70A21CF4FD468B6C69717CC779CFA2D195ADB9F95139BB334E441D0633A18B7475FAEF4CDDF0F1E04FC84B1497EFE544B2F16F6BDD533E6DA444517FBB4A6C016845CF3367E296097B469A3AE6A19C30669DE37BCA1984C5410E631FFEB6DA1CF12654C98B5062C681D49594682938DF1C0E76A08B8F1896FDAB79A2AF4B8E12BD1127E4C8C046E7CA5F02359342114DCC7A9178937865B004BA86B2995045AA8F5505D4824C9855218F44AE83A99DE091DE619E1D6CA9E8A0C7E3E1ACBD3BC1E6354087EA5306328541D77B9E68364EA9FA747C3794F1B90A77350FE5A7DE0B6907339D2C9A3C57A07AECD70EC71CD5371AEE203934A472E5A7FFCB31B01EFF52374D5A7BFA55E8722843ADBBD63183BEE5565C01F51DB47069DA5007D1CF76FDA9070EAF4A12929A66190FC594377D60044F4E1809BD297CB540A90FFEE22F14F8C2754A7F256A5CA07AB451366102ECC7DFF8642CAEE1AFCF0147ECA24C79E9163B6E9FB262D179690F2460F269C3B209FE67737A60DB98B807E1E3147F3A8BBB482BE4BA93372508AD837A\",\r\n + \ \"outputValue\" : \"7665F054F21B50DF62CD3E50AF8EB783E30D271B091DE051212D301E0E3D17FFCF0367DB41CFFD3C51E88BDE0B0621F49EB03435BC373D5D49480941A8B3547E\"\r\n + \ }\r\n}" + http_version: + recorded_at: Mon, 01 Apr 2019 00:00:00 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/cassettes/start_chain_beacon_v2.yml b/spec/cassettes/start_chain_beacon_v2.yml new file mode 100644 index 0000000..4a8fdb1 --- /dev/null +++ b/spec/cassettes/start_chain_beacon_v2.yml @@ -0,0 +1,65 @@ +--- +http_interactions: +- request: + method: get + uri: https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1 + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Cache-Control: + - no-cache, no-store, must-revalidate + Pragma: + - no-cache + Content-Type: + - application/json;charset=ISO-8859-1 + Expires: + - Thu, 01 Jan 1970 00:00:00 GMT + Server: + - Microsoft-IIS/8.5 + X-Frame-Options: + - SAMEORIGIN + - SAMEORIGIN + Date: + - Sat, 06 Apr 2019 14:42:39 GMT + Content-Length: + - '3359' + Strict-Transport-Security: + - max-age=31536000 + body: + encoding: UTF-8 + string: "{\r\n \"pulse\" : {\r\n \"uri\" : \"https://beacon.nist.gov/beacon/2.0/chain/1/pulse/1\",\r\n + \ \"version\" : \"Version 2.0\",\r\n \"cipherSuite\" : 0,\r\n \"period\" + : 60000,\r\n \"certificateId\" : \"5501e3d72bc42f3b96e16de4dcadcb16768e109662bd16d667d5fd9aee585af31bbdc5dd4f53592276064b53dddd76c8f3604b2a41db6e09f78f82bb5d6569e7\",\r\n + \ \"chainIndex\" : 1,\r\n \"pulseIndex\" : 1,\r\n \"timeStamp\" : + \"2018-07-23T19:26:00.000Z\",\r\n \"localRandomValue\" : \"88C3BF231794D4D6654924EF771268AF1DA9C2D6A3EA62A79C42D6399CD9DE811C5C32CA71DE2EC867510A8CE44BE6D8694488BE530C02EEB602D8703A4D294F\",\r\n + \ \"external\" : {\r\n \"sourceId\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\r\n + \ \"statusCode\" : 0,\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ },\r\n \"listValues\" : [ {\r\n \"uri\" : null,\r\n \"type\" + : \"previous\",\r\n \"value\" : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"hour\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"day\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"month\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ }, {\r\n \"uri\" : null,\r\n \"type\" : \"year\",\r\n \"value\" + : \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"\r\n + \ } ],\r\n \"precommitmentValue\" : \"6462C73A8D4913910C5AAA748EA82CD67EB4B73D2B3025121AA61354916CA65B9D25FD5FBECE2583E7C5EB172ECF2740472935A7A9013E6E7C84A9EBD6EFFA15\",\r\n + \ \"statusCode\" : 1,\r\n \"signatureValue\" : \"8FD04C3CB2631064C7917C98B606870D6A38C7CFD05CB589EB5F139471F07C8D553B997B583EC14648A1ECACDF0C0ED5E7C8F888E7F1DAF8D34E697B8A64A969DB92DBC8D49A4085AFA6CA068667677E6442F6E368458DE7E32490BD6C80F79276A1EBBD602B8379936758444214A3B8B5C3BF70A21CF4FD468B6C69717CC779CFA2D195ADB9F95139BB334E441D0633A18B7475FAEF4CDDF0F1E04FC84B1497EFE544B2F16F6BDD533E6DA444517FBB4A6C016845CF3367E296097B469A3AE6A19C30669DE37BCA1984C5410E631FFEB6DA1CF12654C98B5062C681D49594682938DF1C0E76A08B8F1896FDAB79A2AF4B8E12BD1127E4C8C046E7CA5F02359342114DCC7A9178937865B004BA86B2995045AA8F5505D4824C9855218F44AE83A99DE091DE619E1D6CA9E8A0C7E3E1ACBD3BC1E6354087EA5306328541D77B9E68364EA9FA747C3794F1B90A77350FE5A7DE0B6907339D2C9A3C57A07AECD70EC71CD5371AEE203934A472E5A7FFCB31B01EFF52374D5A7BFA55E8722843ADBBD63183BEE5565C01F51DB47069DA5007D1CF76FDA9070EAF4A12929A66190FC594377D60044F4E1809BD297CB540A90FFEE22F14F8C2754A7F256A5CA07AB451366102ECC7DFF8642CAEE1AFCF0147ECA24C79E9163B6E9FB262D179690F2460F269C3B209FE67737A60DB98B807E1E3147F3A8BBB482BE4BA93372508AD837A\",\r\n + \ \"outputValue\" : \"7665F054F21B50DF62CD3E50AF8EB783E30D271B091DE051212D301E0E3D17FFCF0367DB41CFFD3C51E88BDE0B0621F49EB03435BC373D5D49480941A8B3547E\"\r\n + \ }\r\n}" + http_version: + recorded_at: Mon, 01 Apr 2019 00:00:00 GMT +recorded_with: VCR 4.0.0 diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 9a50094..8717a86 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -3,7 +3,7 @@ describe NISTRandomnessBeacon::Client do before do - Timecop.freeze(Time.utc(2018)) + Timecop.freeze(Time.utc(2019, 4, 1)) end after do @@ -13,7 +13,7 @@ describe 'current' do context 'successful response' do subject { - VCR.use_cassette('current_v2') do + VCR.use_cassette('current_beacon_v2') do NISTRandomnessBeacon::Client.new.current end } @@ -38,9 +38,9 @@ describe 'previous' do context 'successful response' do subject { - VCR.use_cassette('previous_v2') do + VCR.use_cassette('previous_beacon_v2') do # NOTE(chaserx): using frozen time above results in 404; this magic number works though - NISTRandomnessBeacon::Client.new(1517179800000).previous + NISTRandomnessBeacon::Client.new.previous end } @@ -64,7 +64,7 @@ describe 'next' do context 'successful response' do subject { - VCR.use_cassette('next_v2') do + VCR.use_cassette('next_beacon_v2') do NISTRandomnessBeacon::Client.new.next end } @@ -89,7 +89,7 @@ describe 'last' do context 'successful response' do subject { - VCR.use_cassette('last_v2') do + VCR.use_cassette('last_beacon_v2') do NISTRandomnessBeacon::Client.new.last end } @@ -114,7 +114,7 @@ describe 'start chain' do context 'successful response' do subject { - VCR.use_cassette('start_chain_v2') do + VCR.use_cassette('start_chain_beacon_v2') do # NOTE(chaserx): using frozen time above results in 404; this magic number works though NISTRandomnessBeacon::Client.new(1517179800000).start_chain end @@ -136,4 +136,29 @@ end end end + + describe 'pulse_in_chain' do + context 'successful response' do + subject { + VCR.use_cassette('pulse_in_chain_beacon_v2') do + NISTRandomnessBeacon::Client.new.pulse_in_chain(chain_index: 1, pulse_index: 1) + end + } + + it 'returns a record object' do + expect(subject).to be_an_instance_of(NISTRandomnessBeacon::Record) + end + end + + context 'problematic response' do + subject { + NISTRandomnessBeacon::Client.new.pulse_in_chain(chain_index: 42, pulse_index: 42) + } + + it 'raises service error' do + stub_request(:get, /.*beacon.nist.gov*./).to_return(status: 500, body: 'stubbed response') + expect{subject}.to raise_error(NISTRandomnessBeacon::ServiceError, 'stubbed response') + end + end + end end