An unofficial, mostly Bitwarden-compatible API server written in Ruby (Sinatra and ActiveRecord)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix broken tests, explicitly cast CipherString to string

+10 -8
+3 -2
lib/bitwarden.rb
··· 19 19 require "openssl" 20 20 21 21 class Bitwarden 22 - class InvalidCipherString < RuntimeError; end 22 + class InvalidCipherString < StandardError; end 23 23 24 24 # convenience methods for hashing/encryption/decryption that the apps do, 25 25 # just so we can test against ··· 144 144 145 145 def self.parse(str) 146 146 if !(m = str.to_s.match(/\A(\d)\.([^|]+)\|(.+)\z/)) 147 - raise InvalidCipherString "invalid CipherString: #{str.inspect}" 147 + raise Bitwarden::InvalidCipherString, "invalid CipherString: " << 148 + str.inspect 148 149 end 149 150 150 151 type = m[1].to_i
+3 -2
lib/cipher.rb
··· 52 52 53 53 # migrate from older style everything-in-data to separate fields 54 54 def migrate_data! 55 - return if !self.data 55 + return false if !self.data 56 56 57 57 js = JSON.parse(self.data) 58 - return if !js 58 + return false if !js 59 59 60 60 self.name = js.delete("Name") 61 61 self.notes = js.delete("Notes") ··· 78 78 self.send("#{fmap[self.type]}=", js) 79 79 80 80 self.save || raise("failed migrating #{self.inspect}") 81 + true 81 82 end 82 83 83 84 def to_hash
+4 -4
spec/user_spec.rb
··· 35 35 c.type = Cipher::TYPE_LOGIN 36 36 37 37 cdata = { 38 - "Name" => u.encrypt_data_with_master_password_key("some name", mk) 38 + "Name" => u.encrypt_data_with_master_password_key("some name", mk).to_s 39 39 } 40 40 41 41 c.data = cdata.to_json 42 - c.migrate_data! 42 + c.migrate_data!.must_equal true 43 43 44 44 c = Cipher.last 45 45 u.decrypt_data_with_master_password_key(c.to_hash["Name"], mk). ··· 56 56 c.type = Cipher::TYPE_LOGIN 57 57 58 58 cdata = { 59 - "Name" => u.encrypt_data_with_master_password_key("some name", mk) 59 + "Name" => u.encrypt_data_with_master_password_key("some name", mk).to_s 60 60 } 61 61 c.data = cdata.to_json 62 - c.migrate_data! 62 + c.migrate_data!.must_equal true 63 63 64 64 u.update_master_password(USER_PASSWORD, USER_PASSWORD + "2") 65 65 u.save.must_equal true