Skip to content

Commit f261088

Browse files
committed
feat: Added unit tests.
1 parent faad12f commit f261088

File tree

27 files changed

+1143
-39
lines changed

27 files changed

+1143
-39
lines changed

.github/workflows/ruby.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,19 @@ jobs:
6161
- name: RuboCop Linter
6262
working-directory: ${{ matrix.dir }}
6363
run: bundle exec rubocop
64+
65+
spec:
66+
runs-on: ubuntu-latest
67+
env:
68+
COVERAGE: 1
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
- name: Set up Ruby
73+
uses: ruby/setup-ruby@v1
74+
with:
75+
bundler-cache: true
76+
working-directory: ${{ matrix.dir }}
77+
- name: Run tests
78+
working-directory: ${{ matrix.dir }}
79+
run: bundle exec rspec

hyperproof/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.csv
22
*.env
3+
coverage/
34
vendor/

hyperproof/.rspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--require spec_helper.rb
2+
--color
3+
--format RSpec::Github::Formatter
4+
--format documentation

hyperproof/.rubocop.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins:
22
- rubocop-performance
33
- rubocop-rake
4+
- rubocop-rspec
45

56
AllCops:
67
NewCops: enable
@@ -10,11 +11,21 @@ AllCops:
1011
Metrics/MethodLength:
1112
CountAsOne:
1213
- array
13-
- method_call
1414
- hash
15+
- method_call
1516

1617
# Exclude our main gem include from the file naming convention, to keep it
1718
# consistent with the gem name.
1819
Naming/FileName:
1920
Exclude:
2021
- 'lib/cfa-security-controls-hyperproof.rb'
22+
23+
RSpec/ExampleLength:
24+
CountAsOne:
25+
- array
26+
- hash
27+
- method_call
28+
29+
# Favor more reusable helpers.
30+
RSpec/MultipleMemoizedHelpers:
31+
Max: 10

hyperproof/Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ group :development do
99
gem 'rubocop', '~> 1.75'
1010
gem 'rubocop-performance', '~> 1.25'
1111
gem 'rubocop-rake', '~> 0.7'
12+
gem 'rubocop-rspec', '~> 3.6'
13+
gem 'rubocop-yard', '~> 0.10'
14+
end
15+
16+
group :development, :test do
17+
gem 'rspec', '~> 3.13'
18+
gem 'rspec-github', '~> 3.0'
19+
gem 'simplecov', '~> 0.22'
1220
end

hyperproof/Gemfile.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ GEM
7474
concurrent-ruby (1.3.4)
7575
connection_pool (2.5.3)
7676
csv (3.3.4)
77+
diff-lcs (1.6.2)
78+
docile (1.4.1)
7779
drb (2.2.1)
7880
faraday (2.13.1)
7981
faraday-net_http (>= 2.0, < 3.5)
@@ -124,6 +126,21 @@ GEM
124126
rainbow (3.1.1)
125127
rake (13.2.1)
126128
regexp_parser (2.10.0)
129+
rspec (3.13.1)
130+
rspec-core (~> 3.13.0)
131+
rspec-expectations (~> 3.13.0)
132+
rspec-mocks (~> 3.13.0)
133+
rspec-core (3.13.4)
134+
rspec-support (~> 3.13.0)
135+
rspec-expectations (3.13.5)
136+
diff-lcs (>= 1.2.0, < 2.0)
137+
rspec-support (~> 3.13.0)
138+
rspec-github (3.0.0)
139+
rspec-core (~> 3.0)
140+
rspec-mocks (3.13.5)
141+
diff-lcs (>= 1.2.0, < 2.0)
142+
rspec-support (~> 3.13.0)
143+
rspec-support (3.13.4)
127144
rubocop (1.75.7)
128145
json (~> 2.3)
129146
language_server-protocol (~> 3.17.0.2)
@@ -145,8 +162,20 @@ GEM
145162
rubocop-rake (0.7.1)
146163
lint_roller (~> 1.1)
147164
rubocop (>= 1.72.1)
165+
rubocop-rspec (3.6.0)
166+
lint_roller (~> 1.1)
167+
rubocop (~> 1.72, >= 1.72.1)
168+
rubocop-yard (0.10.0)
169+
rubocop (~> 1.21)
170+
yard
148171
ruby-progressbar (1.13.0)
149172
securerandom (0.4.1)
173+
simplecov (0.22.0)
174+
docile (~> 1.1)
175+
simplecov-html (~> 0.11)
176+
simplecov_json_formatter (~> 0.1)
177+
simplecov-html (0.13.1)
178+
simplecov_json_formatter (0.1.4)
150179
snaky_hash (2.0.1)
151180
hashie
152181
version_gem (~> 1.1, >= 1.1.1)
@@ -159,6 +188,7 @@ GEM
159188
uri (1.0.3)
160189
uri_template (0.7.0)
161190
version_gem (1.1.8)
191+
yard (0.9.37)
162192

163193
PLATFORMS
164194
arm64-darwin-24
@@ -167,9 +197,14 @@ PLATFORMS
167197
DEPENDENCIES
168198
cfa-security-controls-hyperproof!
169199
rake (~> 13.2)
200+
rspec (~> 3.13)
201+
rspec-github (~> 3.0)
170202
rubocop (~> 1.75)
171203
rubocop-performance (~> 1.25)
172204
rubocop-rake (~> 0.7)
205+
rubocop-rspec (~> 3.6)
206+
rubocop-yard (~> 0.10)
207+
simplecov (~> 0.22)
173208

174209
BUNDLED WITH
175210
2.6.7

hyperproof/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Hyperproof
2+
3+
This is a system to collect evidence (proofs) of our security and compliance
4+
posture, and sync them with our compliance management system ([Hyperproof]).
5+
6+
## Usage
7+
8+
You can run the system from GitHub Actions (recommended), or locally.
9+
10+
### GitHub Actions
11+
12+
Run the [Hyperproof Sync][workflow] from the GitHub Actions tab of this
13+
repository. Alternatively, if you have the [GitHub CLI][gh] installed, you can
14+
run the workflow from the command line:
15+
16+
```bash
17+
gh workflow run hyperproof.yaml
18+
```
19+
20+
### Locally
21+
22+
If you want to run the system locally — to test changes or debug issues, for
23+
example — you will first need to install the necessary dependencies. Use your
24+
favorite ruby version manager to install the required [version of
25+
ruby][ruby-version].
26+
27+
Make sure you've switched to the `hyperproof` directory in the repository, then
28+
install the dependencies using `bundler`:
29+
30+
```bash
31+
cd hyperproof
32+
bundle install
33+
```
34+
35+
You should now be able to run use the provided CLI command. You can check the
36+
current version to verify that everything is working:
37+
38+
```bash
39+
./bin/hyperproof version
40+
```
41+
42+
If you see the version number, you're good to go! You can now run the full
43+
system with:
44+
45+
```bash
46+
./bin/hyperproof collect
47+
```
48+
49+
[gh]: https://cli.github.com/
50+
[hyperproof]: https://hyperproof.io/
51+
[ruby-version]: https://github.com/codeforamerica/cfa-security-controls/tree/main/hyperproof/.ruby-version
52+
[workflow]: https://github.com/codeforamerica/cfa-security-controls/actions/workflows/hyperproof.yaml

hyperproof/Rakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# frozen_string_literal: true
22

33
require 'bundler'
4+
require 'rspec/core/rake_task'
45
require 'rubocop/rake_task'
56

6-
task default: %i[rubocop]
7+
task default: %i[rubocop spec]
78

89
Bundler::GemHelper.install_tasks
910

11+
RSpec::Core::RakeTask.new(:spec)
12+
1013
RuboCop::RakeTask.new(:rubocop) do |task|
1114
task.requires << 'rubocop'
15+
task.formatters = %w[pacman]
16+
task.formatters << 'github' if ENV.fetch('GITHUB_ACTIONS', false)
1217
end

hyperproof/lib/cfa_security_controls/hyperproof.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
module CfaSecurityControls
88
# Top level module for our gem.
99
module Hyperproof
10-
# Collect all proofs without writing them to Hyperproof.
11-
def self.collect
12-
Proofs.proofs.map do |collector|
13-
r = collector.new.collect
14-
pp(r)
15-
end
16-
end
17-
1810
# Collect and upload all proofs to Hyperproof.
1911
def self.run
2012
Dir.mktmpdir do |dir|

hyperproof/lib/cfa_security_controls/hyperproof/clients/aptible.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def token
3838
@token ||= basic_auth_token || sso_token
3939

4040
raise InvalidCredentials, 'No valid Aptible credentials found' unless @token
41+
42+
@token
4143
end
4244

4345
# Retrieve the SSO token from the Aptible token file.

0 commit comments

Comments
 (0)