This commit is contained in:
Eric Hanko 2017-11-16 01:00:11 -08:00
Родитель 671fca2b54
Коммит a671164925
3 изменённых файлов: 17 добавлений и 7 удалений

Просмотреть файл

@ -1,14 +1,12 @@
module KcpasswordHelpers
class Kcpassword << self
def magic_bits
[125, 137, 82, 35, 210, 188, 221, 234, 163, 185, 31]
end
module Kcpassword
@magic_bits = [125, 137, 82, 35, 210, 188, 221, 234, 163, 185, 31]
def obfuscate(password)
obfuscated = []
padded(password).each do |char|
obfuscated.push(@magic_bits[0] ^ char)
@magic_bits.rotate
@magic_bits.rotate!
end
obfuscated.pack('C*')
end
@ -28,5 +26,5 @@ module KcpasswordHelpers
end
end unless defined?(KcpasswordHelpers)
Chef::Recipe.include(KcpasswordHelpers)
Chef::Resource.include(KcpasswordHelpers)
Chef::Recipe.include(KcpasswordHelpers::Kcpassword)
Chef::Resource.include(KcpasswordHelpers::Kcpassword)

Просмотреть файл

@ -3,3 +3,4 @@ require 'chefspec/berkshelf'
require_relative '../libraries/plistbuddy'
require_relative '../libraries/xcode'
require_relative '../libraries/kcpassword'

Просмотреть файл

@ -0,0 +1,11 @@
require 'spec_helper'
include KcpasswordHelpers::Kcpassword
describe KcpasswordHelpers::Kcpassword, '#obfuscate' do
context 'When calling the obfuscate method' do
it 'the password is obfuscated correctly' do
expect(KcpasswordHelpers::Kcpassword.obfuscate('password')).to eq "\r\xE8!P\xA5\xD3\xAF\x8E\xA3\xB9\x1F".force_encoding('ASCII-8BIT')
end
end
end