Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit a01c82e

Browse files
committed
add tests
1 parent 1f55c3c commit a01c82e

File tree

5 files changed

+103
-10
lines changed

5 files changed

+103
-10
lines changed

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
AllCops:
22
TargetRubyVersion: 2.4
33
NewCops: enable
4+
Exclude:
5+
- 'test/*.rb'
6+
SuggestExtensions: false
47
Layout/HashAlignment:
58
Exclude:
69
- '*.gemspec'

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,4 @@ Made by Alexandre ZANNI ([@noraj](https://pwn.by/noraj/)), pentester at [SEC-IT]
4646
## TODO list / Roadmap:
4747

4848
- [ ] CSV, JSON, YAML output formatter
49-
- [x] Asciinema demo
50-
- [ ] publish on rubygems
5149
- [ ] publish on BA & pentoo
52-
- [x] enable GH pages
53-
- [ ] release version 1.0.0
54-
- [ ] Rawsec inventory
55-
- [ ] write tests

Rakefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# frozen_string_literal: true
22

33
require 'rake/testtask'
4-
require 'bundler/gem_tasks'
54

6-
Rake::TestTask.new do |t|
5+
Rake::TestTask.new(:test) do |t|
76
t.libs << 'test'
7+
t.libs << 'lib'
8+
t.test_files = FileList['test/**/test_*.rb']
89
end
910

1011
desc 'Run tests'

lib/pass_station.rb

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module PassStation
1515
class DB
1616
# Get / set storage location, where will be stored the password database.
1717
# @return [String] database storage location. Default to +data/+.
18-
# @example
19-
# PassStation.storage_location = '/srv/downloads/'
2018
attr_accessor :storage_location
2119

2220
# Get / set the password database name

test/test_passstation.rb

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# frozen_string_literal: false
2+
3+
require 'minitest/autorun'
4+
require 'pass_station'
5+
require 'pass_station/output'
6+
7+
# Create a pseudo-Boolean class
8+
module Boolean; end
9+
class TrueClass; include Boolean; end
10+
class FalseClass; include Boolean; end
11+
12+
class PassStattionTest < Minitest::Test
13+
def setup
14+
@ps = PassStation::DB.new
15+
@ps.parse
16+
end
17+
18+
def test_DB_attributes_defaults
19+
ps = PassStation::DB.new
20+
assert_equal('data/', ps.storage_location)
21+
assert_equal('DefaultCreds-Cheat-Sheet.csv', ps.database_name)
22+
assert_nil(ps.data)
23+
end
24+
25+
def test_DB_check_for_update
26+
assert_kind_of(Boolean, PassStation::DB.check_for_update)
27+
end
28+
29+
def test_DB_download_upstream
30+
assert_instance_of(String, PassStation::DB.download_upstream(Dir.mktmpdir))
31+
end
32+
33+
def test_DB_parse
34+
assert_instance_of(Array, @ps.parse)
35+
assert_instance_of(CSV::Row, @ps.parse[0])
36+
assert_instance_of(Array, @ps.parse(:username))
37+
assert_instance_of(CSV::Row, @ps.parse(:password)[0])
38+
end
39+
40+
def test_DB_search
41+
# exists
42+
assert_instance_of(Array, @ps.search('zyxel', :productvendor))
43+
assert_instance_of(CSV::Row, @ps.search('zyxel', :productvendor)[0])
44+
# Doesn't exist
45+
assert_empty(@ps.search('xdshfiuds6567557657', :username))
46+
end
47+
48+
def test_DB_output
49+
# Types
50+
assert_instance_of(Array, @ps.output('table', @ps.data))
51+
assert_instance_of(Array, @ps.output('pretty-table', @ps.data))
52+
assert_instance_of(String, @ps.output('table', @ps.data)[0])
53+
assert_instance_of(String, @ps.output('pretty-table', @ps.data)[0])
54+
# Headers
55+
assert(@ps.output('table', @ps.data)[0].match?(/productvendor\s+username\s+password\s+/))
56+
assert(@ps.output('pretty-table', @ps.data)[0].match?(/\+-+\+-+\+-+\+/))
57+
assert(@ps.output('pretty-table', @ps.data)[1].match?(/|\sproductvendor\s+|\susername\+|\spassword\s+|/))
58+
end
59+
60+
def test_DB_output_list
61+
assert_instance_of(Array, @ps.output_list('table'))
62+
assert_instance_of(Array, @ps.output_list('pretty-table'))
63+
assert_instance_of(String, @ps.output_list('table')[0])
64+
assert_instance_of(String, @ps.output_list('pretty-table')[0])
65+
end
66+
67+
def test_DB_output_search
68+
@ps.search('cisco', :all, sensitive: true)
69+
assert_instance_of(Array, @ps.output_search('table'))
70+
assert_instance_of(Array, @ps.output_search('pretty-table'))
71+
assert_instance_of(String, @ps.output_search('table')[0])
72+
assert_instance_of(String, @ps.output_search('pretty-table')[0])
73+
end
74+
75+
def test_DB_highlight_found
76+
# String
77+
@ps.search('Apache', :all, sensitive: true)
78+
output = @ps.output_search('table')
79+
assert_instance_of(Array, @ps.highlight_found('Apache', output, sensitive: true))
80+
assert_instance_of(String, @ps.highlight_found('Apache', output, sensitive: true)[0])
81+
# Regexp
82+
@ps.search('password[0-9]+', :password)
83+
output = @ps.output_search('table')
84+
assert_instance_of(Array, @ps.highlight_found('password[0-9]+', output, sensitive: false))
85+
assert_instance_of(String, @ps.highlight_found('password[0-9]+', output, sensitive: false)[0])
86+
end
87+
88+
def test_Output_Table_format
89+
assert_instance_of(Array, PassStation::Output::Table.format(@ps.data))
90+
assert_instance_of(String, PassStation::Output::Table.format(@ps.data)[0])
91+
end
92+
93+
def test_Output_PrettyTable_format
94+
assert_instance_of(Array, PassStation::Output::PrettyTable.format(@ps.data))
95+
assert_instance_of(String, PassStation::Output::PrettyTable.format(@ps.data)[0])
96+
end
97+
end

0 commit comments

Comments
 (0)