fix weird /dev/random behavior

This commit is contained in:
nitram 2019-02-28 12:17:59 -08:00
parent 9753a3cd9f
commit 224e98d9cf
No known key found for this signature in database
GPG key ID: 2352C35346C5D534
2 changed files with 20 additions and 20 deletions

View file

@ -27,7 +27,7 @@ build:
- export REDIS_URI=$REDIS_URI_CI - export REDIS_URI=$REDIS_URI_CI
script: script:
- bundle exec rake db:create && bundle exec rake db:schema:load && bundle exec rake db:migrate - bundle exec rake db:create && bundle exec rake db:schema:load && bundle exec rake db:migrate
- bundle exec ruby tests/tests.rb || echo "Tests failed.." && exit 1 - bundle exec ruby tests/tests.rb || { echo "Tests failed.."; exit 1; }
- echo $DOCKERHUB_PW | docker login -u $DOCKERHUB_USER --password-stdin - echo $DOCKERHUB_PW | docker login -u $DOCKERHUB_USER --password-stdin
- docker pull blockstream/satellite-api:latest - docker pull blockstream/satellite-api:latest
- docker pull blockstream/satellite-api-sse:latest - docker pull blockstream/satellite-api-sse:latest

View file

@ -10,50 +10,50 @@ TEST_FILE = "test.random"
TINY_TEST_FILE = "zero_length_test_file.txt" TINY_TEST_FILE = "zero_length_test_file.txt"
unless File.exists?(TEST_FILE) and File.exists?(TINY_TEST_FILE) unless File.exists?(TEST_FILE) and File.exists?(TINY_TEST_FILE)
`dd if=/dev/random of=#{TEST_FILE} bs=1k count=#{MAX_MESSAGE_SIZE / KILO_BYTE}` `dd if=/dev/urandom of=#{TEST_FILE} bs=1k count=#{MAX_MESSAGE_SIZE / KILO_BYTE}`
`touch #{TINY_TEST_FILE}` `touch #{TINY_TEST_FILE}`
end end
DEFAULT_BID = File.stat(TEST_FILE).size * (MIN_PER_BYTE_BID + 1) DEFAULT_BID = File.stat(TEST_FILE).size * (MIN_PER_BYTE_BID + 1)
class MainAppTest < Minitest::Test class MainAppTest < Minitest::Test
include Rack::Test::Methods include Rack::Test::Methods
def app def app
Sinatra::Application Sinatra::Application
end end
def place_order(bid = DEFAULT_BID) def place_order(bid = DEFAULT_BID)
post '/order', params={"bid" => bid, "file" => Rack::Test::UploadedFile.new(TEST_FILE, "image/png")} post '/order', params={"bid" => bid, "file" => Rack::Test::UploadedFile.new(TEST_FILE, "image/png")}
r = JSON.parse(last_response.body) r = JSON.parse(last_response.body)
Order.find_by_uuid(r['uuid']) Order.find_by_uuid(r['uuid'])
end end
def bump_order(order, amount) def bump_order(order, amount)
header 'X-Auth-Token', order.user_auth_token header 'X-Auth-Token', order.user_auth_token
post "/order/#{order.uuid}/bump", params={"bid_increase" => amount} post "/order/#{order.uuid}/bump", params={"bid_increase" => amount}
r = JSON.parse(last_response.body) r = JSON.parse(last_response.body)
r['lightning_invoice'] r['lightning_invoice']
end end
def setup def setup
@order = place_order @order = place_order
end end
def pay_invoice(invoice) def pay_invoice(invoice)
post "/callback/#{invoice.lid}/#{invoice.charged_auth_token}" post "/callback/#{invoice.lid}/#{invoice.charged_auth_token}"
assert last_response.ok? assert last_response.ok?
end end
def write_response def write_response
File.open('response.html', 'w') { |file| file.write(last_response.body) } File.open('response.html', 'w') { |file| file.write(last_response.body) }
end end
def last_response_error_code def last_response_error_code
r = JSON.parse(last_response.body) r = JSON.parse(last_response.body)
Integer(r["errors"].first["code"]) Integer(r["errors"].first["code"])
end end
def order_is_queued(uuid) def order_is_queued(uuid)
get "/orders/queued?limit=#{MAX_PAGE_SIZE}" get "/orders/queued?limit=#{MAX_PAGE_SIZE}"
assert last_response.ok? assert last_response.ok?
@ -95,7 +95,7 @@ class MainAppTest < Minitest::Test
get %Q(/order/#{r['uuid']}) get %Q(/order/#{r['uuid']})
assert last_response.ok? assert last_response.ok?
end end
def test_order_creation def test_order_creation
place_order place_order
assert last_response.ok? assert last_response.ok?
@ -126,13 +126,13 @@ class MainAppTest < Minitest::Test
refute last_response.ok? refute last_response.ok?
assert_equal ERROR::CODES[:BID_TOO_SMALL], last_response_error_code assert_equal ERROR::CODES[:BID_TOO_SMALL], last_response_error_code
end end
def test_bid_too_low def test_bid_too_low
post '/order', params={"bid" => 1, "file" => Rack::Test::UploadedFile.new(TEST_FILE, "image/png")} post '/order', params={"bid" => 1, "file" => Rack::Test::UploadedFile.new(TEST_FILE, "image/png")}
refute last_response.ok? refute last_response.ok?
assert_equal ERROR::CODES[:BID_TOO_SMALL], last_response_error_code assert_equal ERROR::CODES[:BID_TOO_SMALL], last_response_error_code
end end
def test_order_without_message def test_order_without_message
post '/order', params={"bid" => DEFAULT_BID} post '/order', params={"bid" => DEFAULT_BID}
refute last_response.ok? refute last_response.ok?
@ -148,7 +148,7 @@ class MainAppTest < Minitest::Test
refute last_response.ok? refute last_response.ok?
assert_equal ERROR::CODES[:MESSAGE_FILE_TOO_SMALL], last_response_error_code assert_equal ERROR::CODES[:MESSAGE_FILE_TOO_SMALL], last_response_error_code
end end
def test_bid_increase_missing_error def test_bid_increase_missing_error
header 'X-Auth-Token', @order.user_auth_token header 'X-Auth-Token', @order.user_auth_token
post "/order/#{@order.uuid}/bump" post "/order/#{@order.uuid}/bump"
@ -161,7 +161,7 @@ class MainAppTest < Minitest::Test
refute last_response.ok? refute last_response.ok?
assert_equal ERROR::CODES[:BID_INCREASE_TOO_SMALL], last_response_error_code assert_equal ERROR::CODES[:BID_INCREASE_TOO_SMALL], last_response_error_code
end end
def test_invalid_auth_token_error def test_invalid_auth_token_error
header 'X-Auth-Token', "not an auth token" header 'X-Auth-Token', "not an auth token"
post "/order/#{@order.uuid}/bump", params={"bid_increase" => DEFAULT_BID / 2} post "/order/#{@order.uuid}/bump", params={"bid_increase" => DEFAULT_BID / 2}
@ -248,7 +248,7 @@ class MainAppTest < Minitest::Test
delete "/order/#{@order.uuid}" delete "/order/#{@order.uuid}"
refute last_response.ok? refute last_response.ok?
end end
def test_get_sent_message def test_get_sent_message
@order = place_order @order = place_order
get "/order/#{@order.uuid}/sent_message" get "/order/#{@order.uuid}/sent_message"
@ -260,17 +260,17 @@ class MainAppTest < Minitest::Test
@order.transmit! @order.transmit!
get "/order/#{@order.uuid}/sent_message" get "/order/#{@order.uuid}/sent_message"
assert last_response.ok? assert last_response.ok?
@order.end_transmission! @order.end_transmission!
get "/order/#{@order.uuid}/sent_message" get "/order/#{@order.uuid}/sent_message"
assert last_response.ok? assert last_response.ok?
end end
def test_channel_subscription def test_channel_subscription
get "/subscribe/not_a_channel" get "/subscribe/not_a_channel"
refute last_response.ok? refute last_response.ok?
assert_equal ERROR::CODES[:CHANNELS_EQUALITY], last_response_error_code assert_equal ERROR::CODES[:CHANNELS_EQUALITY], last_response_error_code
end end
end end