An unofficial, mostly Bitwarden-compatible API server written in Ruby (Sinatra and ActiveRecord)
at master 53 lines 1.2 kB view raw
1ENV["RUBYWARDEN_ENV"] = "test" 2 3# most tests require this to be on 4ENV["RUBYWARDEN_ALLOW_SIGNUPS"] = "1" 5 6require "minitest/autorun" 7require "rack/test" 8require "open3" 9 10require File.realpath(File.dirname(__FILE__) + "/../lib/rubywarden.rb") 11require "#{APP_ROOT}/lib/app.rb" 12 13if File.exist?(_f = ActiveRecord::Base.connection_config[:database]) 14 File.unlink(_f) 15end 16 17ActiveRecord::Migration.verbose = false 18ActiveRecord::Migrator.up "db/migrate" 19 20# in case migrations changed what we're testing 21[ Attachment, User, Cipher, Device, Folder ].each do |c| 22 c.send(:reset_column_information) 23end 24 25include Rack::Test::Methods 26 27Dir[Rubywarden::App.settings.root + '/spec/support/**/*.rb'].sort.each { |f| require f } 28include Rubywarden::Test::RequestHelpers 29 30 31def app 32 Rubywarden::App 33end 34 35def run_command_and_send_password(cmd, password) 36 Open3.popen3(*cmd) do |i,o,e,t| 37 i.puts password 38 i.close_write 39 40 files = [ e ] 41 while files.any? 42 if ready = IO.select([ e ]) 43 ready[0].each do |f| 44 begin 45 puts "STDERR: #{f.read_nonblock(1024).inspect}" 46 rescue EOFError => e 47 files.delete f 48 end 49 end 50 end 51 end 52 end 53end