-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
416 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
require "functional/helper" | ||
require "fileutils" | ||
require "tmpdir" | ||
|
||
describe "running profiles with git-based dependencies" do | ||
include FunctionalHelper | ||
let(:git_profiles) { "#{profile_path}/git-fetcher" } | ||
|
||
#======================================================================# | ||
# Git Repo Setup | ||
#======================================================================# | ||
fixture_repos = ["basic-local", "git-repo-01"] | ||
|
||
before(:all) do | ||
skip_windows! # Right now, this is due to symlinking | ||
|
||
# We need a git repo for some of the profile test fixtures, | ||
# but we can't store those directly in git. | ||
# Here, one approach is to store the .git/ directory under a | ||
# different name and then symlink to its proper name. | ||
fixture_repos.each do |profile_name| | ||
link_src = "#{git_profiles}/#{profile_name}/git-fixture" | ||
link_dst = "#{git_profiles}/#{profile_name}/.git" | ||
FileUtils.ln_sf(link_src, link_dst) # -f to tolerate existing links created during manual testing | ||
end | ||
end | ||
|
||
after(:all) do | ||
fixture_repos.each do |profile_name| | ||
link = "#{git_profiles}/#{profile_name}/.git" | ||
FileUtils.rm(link) | ||
end | ||
end | ||
|
||
#======================================================================# | ||
# Custom Local Assertions | ||
#======================================================================# | ||
def assert_relative_fetch_works(profile_name, expected_profiles, expected_controls) | ||
run_result = run_inspec_process("exec #{git_profiles}/#{profile_name}", json: true) | ||
assert_empty run_result.stderr | ||
run_result.must_have_all_controls_passing | ||
|
||
# Should know about the top-level profile and the child profile | ||
assert_equal expected_profiles, (run_result.payload.json["profiles"].map { |p| p["name"] }) | ||
|
||
controls = run_result.payload.json["profiles"].map { |p| p["controls"] }.flatten.map { |c| c["id"] }.uniq | ||
# Should have controls from the top-level and included child profile | ||
expected_controls.each { |control| assert_includes controls, control } | ||
|
||
# should not have controls from the profile defined at the top of the repo of the child profile | ||
refute_includes controls, "red-dye" | ||
end | ||
|
||
#======================================================================# | ||
# Basic Git Fetching | ||
#======================================================================# | ||
describe "running a profile with a basic local dependency" do | ||
it "should work on a local checkout" do | ||
run_result = run_inspec_process("exec #{git_profiles}/basic-local", json: true) | ||
assert_empty run_result.stderr | ||
run_result.must_have_all_controls_passing | ||
end | ||
end | ||
# describe "running a profile with a basic remote dependency" | ||
|
||
# TODO: move private SSH+git test from inspec_exec_test to here | ||
|
||
#======================================================================# | ||
# Revision Selection | ||
#======================================================================# | ||
# TODO: test branch, rev, and tag capabilities | ||
|
||
#======================================================================# | ||
# Relative Path Support | ||
#======================================================================# | ||
|
||
#------------ Happy Cases for Relative Path Support -------------------# | ||
describe "running a profile with a shallow relative path dependency" do | ||
it "should find the relative path profile and execute exactly those controls" do | ||
assert_relative_fetch_works("relative-shallow", ["relative-shallow", "child-01"], ["top-level-01", "child-01"]) | ||
end | ||
end | ||
|
||
describe "running a profile with a deep relative path dependency" do | ||
it "should find the relative path profile and execute exactly those controls" do | ||
assert_relative_fetch_works("relative-deep", ["relative-deep", "child-02"], ["relative-deep-01", "child-02"]) | ||
end | ||
end | ||
|
||
describe "running a profile with a combination of relative path dependencies" do | ||
it "should find the relative path profiles and execute exactly those controls" do | ||
assert_relative_fetch_works( | ||
"relative-combo", | ||
["relative-combo", "child-01", "child-02"], | ||
["relative-combo-01", "child-01", "child-02"] | ||
) | ||
end | ||
end | ||
|
||
#------------ Edge Cases for Relative Path Support -------------------# | ||
|
||
# TODO: These next two tests trigger a bug, in which the profile appears | ||
# to have a key collision in the cache. | ||
|
||
describe "running a profile with an '' relative path dependency" do | ||
it "should find the top-level profile in the git-referenced child profile and execute that" do | ||
assert_relative_fetch_works("relative-empty", ["relative-empty", "basic-local"], ["relative-empty-01", "basic-local-01"]) | ||
end | ||
end | ||
|
||
describe "running a profile with an ./ relative path dependency" do | ||
it "should find the top-level profile in the git-referenced child profile and execute that" do | ||
assert_relative_fetch_works("relative-dot-slash", ["relative-dot-slash", "basic-local"], ["relative-dot-slash-01", "basic-local-01"]) | ||
end | ||
end | ||
|
||
describe "running a profile with a relative path dependency that does not exist" do | ||
it "should fail gracefully" do | ||
run_result = run_inspec_process("exec #{git_profiles}/relative-nonesuch") | ||
assert_exit_code(1, run_result) # General user error | ||
assert_empty run_result.stdout | ||
refute_includes run_result.stderr, "Errno::ENOENT" # No ugly file missing error | ||
assert_equal 1, run_result.stderr.lines.count # Not a giant stacktrace | ||
# Spot check important parts of the message | ||
assert_includes run_result.stderr, "Cannot find relative path" | ||
assert_includes run_result.stderr, "no/such/path" # the actual missing path | ||
assert_includes run_result.stderr, "profile in git repo" | ||
# The containing git repo (the only identifier the user will have) | ||
assert_includes run_result.stderr, "test/unit/mock/profiles/git-fetcher/git-repo-01" | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a git repo used as a test fixture. Because we cannot directly store the .git/ directory, it is stored as git-fixture/, and a symlink is created at test runtime. |
5 changes: 5 additions & 0 deletions
5
test/unit/mock/profiles/git-fetcher/basic-local/controls/basic-local.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
control 'basic-local-01' do | ||
describe 'always-pass' do | ||
it { should cmp 'always-pass'} | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/COMMIT_EDITMSG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add change only on one branch |
1 change: 1 addition & 0 deletions
1
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/HEAD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ref: refs/heads/master |
10 changes: 10 additions & 0 deletions
10
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[core] | ||
repositoryformatversion = 0 | ||
filemode = true | ||
bare = false | ||
logallrefupdates = true | ||
ignorecase = true | ||
precomposeunicode = true | ||
[user] | ||
name = test user | ||
email = test@test.org |
1 change: 1 addition & 0 deletions
1
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Unnamed repository; edit this file 'description' to name the repository. |
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/info/exclude
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# git ls-files --others --exclude-from=.git/info/exclude | ||
# Lines that start with '#' are comments. | ||
# For a project mostly in C, the following would be a good set of | ||
# exclude patterns (uncomment them if you want to use them): | ||
# *.[oa] | ||
# *~ |
4 changes: 4 additions & 0 deletions
4
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/logs/HEAD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0000000000000000000000000000000000000000 0e7d2b9c2c5a1372341e36febceab86558439149 test user <test@test.org> 1560485536 -0400 commit (initial): Initial commit | ||
0e7d2b9c2c5a1372341e36febceab86558439149 0e7d2b9c2c5a1372341e36febceab86558439149 test user <test@test.org> 1560485563 -0400 checkout: moving from master to test-branch | ||
0e7d2b9c2c5a1372341e36febceab86558439149 54d0671d3e2c4a28865a0ecc98863859bd4d7475 test user <test@test.org> 1560485674 -0400 commit: Add change only on one branch | ||
54d0671d3e2c4a28865a0ecc98863859bd4d7475 0e7d2b9c2c5a1372341e36febceab86558439149 test user <test@test.org> 1560485682 -0400 checkout: moving from test-branch to master |
1 change: 1 addition & 0 deletions
1
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/logs/refs/heads/master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0000000000000000000000000000000000000000 0e7d2b9c2c5a1372341e36febceab86558439149 test user <test@test.org> 1560485536 -0400 commit (initial): Initial commit |
2 changes: 2 additions & 0 deletions
2
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/logs/refs/heads/test-branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
0000000000000000000000000000000000000000 0e7d2b9c2c5a1372341e36febceab86558439149 test user <test@test.org> 1560485563 -0400 branch: Created from HEAD | ||
0e7d2b9c2c5a1372341e36febceab86558439149 54d0671d3e2c4a28865a0ecc98863859bd4d7475 test user <test@test.org> 1560485674 -0400 commit: Add change only on one branch |
Binary file added
BIN
+59 Bytes
...les/git-fetcher/basic-local/git-fixture/objects/02/145c02bed66651584950fd3c56a0f8e08495ad
Binary file not shown.
Binary file added
BIN
+124 Bytes
...les/git-fetcher/basic-local/git-fixture/objects/0e/7d2b9c2c5a1372341e36febceab86558439149
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
...les/git-fetcher/basic-local/git-fixture/objects/26/dec4a490f980527c06528510ed85512fd55e10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
x��� | ||
�0D;�+n�$h��{$��j+���o | ||
] | ||
;�-��'�y����6ܐ��)�+���� (5t4��lwރV��l@��@,~�������^�;�e&�E2���W�kI |
2 changes: 2 additions & 0 deletions
2
...les/git-fetcher/basic-local/git-fixture/objects/38/b63f30119439953105a30b6b54201ccdf161ad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
xU�� | ||
�0��o�T�����HS��.7�]M�c�X��T�Y� �$!�Y��q�����tY���s@��a���������-��{�# |
Binary file added
BIN
+59 Bytes
...les/git-fetcher/basic-local/git-fixture/objects/53/7a2ff34c95a18643627a95ae39b1af3f645346
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
...les/git-fetcher/basic-local/git-fixture/objects/54/d0671d3e2c4a28865a0ecc98863859bd4d7475
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
x��Q | ||
�0D��)�J��&)��Q�Ͷl+i���m��0<�cfx��g�xjUrȎ�3��I,Qo��X��\<��A�S����P0w�L�����̒r�D��θN���K�&k�m� | ||
���\�:����.���i��7���?J�Q | ||
��A`�_���_5�<�/{fHJ |
Binary file added
BIN
+89 Bytes
...les/git-fetcher/basic-local/git-fixture/objects/b7/b45291b2ed5c7885e355f12dd8da6bcd6c2437
Binary file not shown.
Binary file added
BIN
+130 Bytes
...les/git-fetcher/basic-local/git-fixture/objects/d4/7c4fc2bd4c7e35dc5e1f40885335cc63bcd241
Binary file not shown.
Binary file added
BIN
+89 Bytes
...les/git-fetcher/basic-local/git-fixture/objects/ea/56cd2cd0923474011fb248a3cd3c2a18585b5f
Binary file not shown.
1 change: 1 addition & 0 deletions
1
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/refs/heads/master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0e7d2b9c2c5a1372341e36febceab86558439149 |
1 change: 1 addition & 0 deletions
1
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/refs/heads/test-branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
54d0671d3e2c4a28865a0ecc98863859bd4d7475 |
1 change: 1 addition & 0 deletions
1
test/unit/mock/profiles/git-fetcher/basic-local/git-fixture/refs/tags/v1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0e7d2b9c2c5a1372341e36febceab86558439149 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: basic-local | ||
title: basic-local | ||
license: Apache-2.0 | ||
summary: A profile to be executed as a local git checkout | ||
version: 0.1.0 | ||
supports: | ||
platform: os | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a git repo used as a test fixture. Because we cannot directly store the .git/ directory, it is stored as git-fixture/, and a symlink is created at test runtime. |
5 changes: 5 additions & 0 deletions
5
test/unit/mock/profiles/git-fetcher/git-repo-01/child-01/controls/child-01.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
control 'child-01' do | ||
describe 'always-pass' do | ||
it { should cmp 'always-pass'} | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
test/unit/mock/profiles/git-fetcher/git-repo-01/child-01/inspec.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: child-01 | ||
title: child-01 | ||
license: Apache-2.0 | ||
summary: A profile to be included via git and a relative path | ||
version: 0.1.0 | ||
supports: | ||
platform: os | ||
|
11 changes: 11 additions & 0 deletions
11
test/unit/mock/profiles/git-fetcher/git-repo-01/controls/red-dye.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This control would only appear if it were accidentally included | ||
control 'red-dye' do | ||
# In rural areas where diesel fuel is sold for | ||
# agricultrual purposes and is exempt from taxation (as part | ||
# of farm subsidies), tractor diesel fuel is dyed red. Highway | ||
# patrol officers check for red dye in the fuel when they | ||
# stop grain hauling trucks, as it is a form of tax fraud. | ||
describe 'truck fuel color' do | ||
it { should cmp 'clear' } | ||
end | ||
end |
Oops, something went wrong.