1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
require 'spec_helper'
require 'rotp/arguments'
RSpec.describe ROTP::Arguments do
let(:arguments) { described_class.new filename, argv }
let(:argv) { '' }
let(:filename) { 'rotp' }
let(:options) { arguments.options }
context 'without options' do
describe '#help' do
it 'shows the help text' do
expect(arguments.to_s).to include 'Usage: '
end
end
describe '#options' do
it 'has the default options' do
expect(options.mode).to eq :time
expect(options.secret).to be_nil
expect(options.counter).to eq 0
end
end
end
context 'unknown arguments' do
let(:argv) { %w[--does-not-exist -xyz] }
describe '#options' do
it 'is in help mode' do
expect(options.mode).to eq :help
end
it 'knows about the problem' do
expect(options.warnings).to include 'invalid option: --does-not-exist'
end
end
end
context 'no arguments' do
let(:argv) { [] }
describe '#options' do
it 'is in help mode' do
expect(options.mode).to eq :help
end
end
end
context 'asking for help' do
let(:argv) { %w[--help] }
describe '#options' do
it 'is in help mode' do
expect(options.mode).to eq :help
end
end
end
context 'generating a counter based secret' do
let(:argv) { %w[--hmac --secret s3same] }
describe '#options' do
it 'is in hmac mode' do
expect(options.mode).to eq :hmac
end
it 'knows the secret' do
expect(options.secret).to eq 's3same'
end
end
end
context 'generating a counter based secret' do
let(:argv) { %w[--time --secret s3same] }
describe '#options' do
it 'is in hmac mode' do
expect(options.mode).to eq :time
end
it 'knows the secret' do
expect(options.secret).to eq 's3same'
end
end
end
context 'generating a time based secret' do
let(:argv) { %w[--secret s3same] }
describe '#options' do
it 'is in time mode' do
expect(options.mode).to eq :time
end
it 'knows the secret' do
expect(options.secret).to eq 's3same'
end
end
end
end
|