right_scraper 1.0.26 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. data/Gemfile +16 -0
  2. data/README.rdoc +9 -28
  3. data/Rakefile +51 -39
  4. data/lib/right_scraper/builders/base.rb +64 -0
  5. data/lib/right_scraper/builders/filesystem.rb +96 -0
  6. data/lib/right_scraper/builders/union.rb +57 -0
  7. data/lib/right_scraper/logger.rb +102 -0
  8. data/lib/right_scraper/loggers/noisy.rb +85 -0
  9. data/lib/right_scraper/processes/ssh.rb +188 -0
  10. data/lib/right_scraper/repositories/base.rb +299 -0
  11. data/lib/right_scraper/repositories/download.rb +90 -0
  12. data/lib/right_scraper/repositories/git.rb +92 -0
  13. data/lib/right_scraper/repositories/mock.rb +70 -0
  14. data/lib/right_scraper/repositories/svn.rb +96 -0
  15. data/lib/right_scraper/resources/base.rb +70 -0
  16. data/{spec/scraper_base_spec.rb → lib/right_scraper/resources/cookbook.rb} +9 -23
  17. data/lib/right_scraper/resources/workflow.rb +55 -0
  18. data/lib/right_scraper/retrievers/base.rb +114 -0
  19. data/lib/right_scraper/retrievers/checkout.rb +79 -0
  20. data/lib/right_scraper/retrievers/download.rb +97 -0
  21. data/lib/right_scraper/retrievers/git.rb +140 -0
  22. data/lib/right_scraper/retrievers/svn.rb +87 -0
  23. data/lib/right_scraper/scanners/base.rb +111 -0
  24. data/lib/right_scraper/scanners/cookbook_manifest.rb +59 -0
  25. data/lib/right_scraper/scanners/cookbook_metadata.rb +69 -0
  26. data/lib/right_scraper/scanners/cookbook_s3_upload.rb +84 -0
  27. data/lib/right_scraper/scanners/union.rb +89 -0
  28. data/lib/right_scraper/scanners/workflow_manifest.rb +86 -0
  29. data/lib/right_scraper/scanners/workflow_metadata.rb +70 -0
  30. data/lib/right_scraper/scanners/workflow_s3_upload.rb +85 -0
  31. data/lib/right_scraper/scraper.rb +81 -57
  32. data/lib/right_scraper/scraper_logger.rb +61 -0
  33. data/lib/right_scraper/scrapers/base.rb +262 -0
  34. data/lib/right_scraper/scrapers/cookbook.rb +73 -0
  35. data/lib/right_scraper/scrapers/workflow.rb +88 -0
  36. data/lib/right_scraper/svn_client.rb +101 -0
  37. data/lib/right_scraper/version.rb +28 -0
  38. data/lib/right_scraper.rb +35 -11
  39. data/right_scraper.gemspec +26 -13
  40. data/right_scraper.rconf +13 -0
  41. data/spec/builder_spec.rb +50 -0
  42. data/spec/cookbook_helper.rb +73 -0
  43. data/spec/cookbook_manifest_spec.rb +55 -0
  44. data/spec/cookbook_s3_upload_spec.rb +152 -0
  45. data/spec/download/download_retriever_spec.rb +118 -0
  46. data/spec/download/download_retriever_spec_helper.rb +72 -0
  47. data/spec/download/download_spec.rb +130 -0
  48. data/spec/download/multi_dir_spec.rb +106 -0
  49. data/spec/download/multi_dir_spec_helper.rb +40 -0
  50. data/spec/git/cookbook_spec.rb +166 -0
  51. data/spec/git/demokey +27 -0
  52. data/spec/git/demokey.pub +1 -0
  53. data/spec/git/password_key +30 -0
  54. data/spec/git/password_key.pub +1 -0
  55. data/spec/git/repository_spec.rb +110 -0
  56. data/spec/git/retriever_spec.rb +505 -0
  57. data/spec/git/retriever_spec_helper.rb +112 -0
  58. data/spec/git/scraper_spec.rb +136 -0
  59. data/spec/git/ssh_spec.rb +170 -0
  60. data/spec/git/url_spec.rb +103 -0
  61. data/spec/logger_spec.rb +185 -0
  62. data/spec/repository_spec.rb +89 -23
  63. data/spec/{scraper_spec_helper_base.rb → retriever_spec_helper.rb} +41 -27
  64. data/spec/scanner_spec.rb +61 -0
  65. data/spec/scraper_helper.rb +96 -0
  66. data/spec/scraper_spec.rb +123 -45
  67. data/spec/spec_helper.rb +87 -14
  68. data/spec/svn/cookbook_spec.rb +97 -0
  69. data/spec/svn/multi_svn_spec.rb +64 -0
  70. data/spec/svn/multi_svn_spec_helper.rb +40 -0
  71. data/spec/svn/repository_spec.rb +72 -0
  72. data/spec/svn/retriever_spec.rb +261 -0
  73. data/spec/svn/scraper_spec.rb +90 -0
  74. data/spec/svn/{svn_scraper_spec_helper.rb → svn_retriever_spec_helper.rb} +46 -27
  75. data/spec/svn/url_spec.rb +47 -0
  76. data/spec/url_spec.rb +164 -0
  77. metadata +203 -31
  78. data/lib/right_scraper/linux/process_monitor.rb +0 -84
  79. data/lib/right_scraper/repository.rb +0 -78
  80. data/lib/right_scraper/scraper_base.rb +0 -175
  81. data/lib/right_scraper/scrapers/download_scraper.rb +0 -67
  82. data/lib/right_scraper/scrapers/git_scraper.rb +0 -283
  83. data/lib/right_scraper/scrapers/svn_scraper.rb +0 -119
  84. data/lib/right_scraper/watcher.rb +0 -158
  85. data/lib/right_scraper/win32/process_monitor.rb +0 -98
  86. data/spec/download/download_scraper_spec.rb +0 -94
  87. data/spec/git/git_scraper_spec.rb +0 -165
  88. data/spec/git/git_scraper_spec_helper.rb +0 -72
  89. data/spec/rcov.opts +0 -1
  90. data/spec/spec.opts +0 -2
  91. data/spec/svn/svn_scraper_spec.rb +0 -148
  92. data/spec/watcher_spec.rb +0 -74
@@ -0,0 +1,130 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'cookbook_helper'))
24
+
25
+ describe RightScraper::Resources::Cookbook do
26
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
27
+
28
+ include RightScraper::CookbookHelper
29
+
30
+ shared_examples_for 'a download repository' do
31
+ it_should_behave_like 'a generic repository'
32
+
33
+ it 'should have no tag' do
34
+ parse_url(@repository)[:tag].should be_nil
35
+ end
36
+ it 'should have no position' do
37
+ parse_url(@repository)[:position].should be_nil
38
+ end
39
+ it 'should have no credentials' do
40
+ parse_url(@repository)[:username].should be_nil
41
+ parse_url(@repository)[:password].should be_nil
42
+ end
43
+ end
44
+
45
+ context 'with a download repository' do
46
+ before(:each) do
47
+ @repository = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
48
+ :repo_type => :download,
49
+ :url => "http://a.site/foo/bar/baz",
50
+ :first_credential => "user",
51
+ :second_credential => "password")
52
+ end
53
+
54
+ it_should_behave_like 'a download repository'
55
+
56
+ it 'should have a cookbook hash' do
57
+ checkout_hash =
58
+ Digest::SHA1.hexdigest("1\000download\000http://a.site/foo/bar/baz\000")
59
+ example_cookbook(@repository).resource_hash.should ==
60
+ Digest::SHA1.hexdigest("1\000#{checkout_hash}\000")
61
+ end
62
+
63
+ it 'should have a cookbook hash invariant under credential changes' do
64
+ old_hash = example_cookbook(@repository).resource_hash
65
+ @repository.first_credential = "b-key"
66
+ example_cookbook(@repository).resource_hash.should == old_hash
67
+ end
68
+
69
+ it 'should have a cookbook hash that varies when the position changes' do
70
+ example_cookbook(@repository, "foo").resource_hash.should_not ==
71
+ example_cookbook(@repository, "bar").resource_hash
72
+ end
73
+ end
74
+
75
+ context 'with a download repository with a port' do
76
+ before(:each) do
77
+ @repository = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
78
+ :repo_type => :download,
79
+ :url => "http://a.site:23/foo/bar/baz",
80
+ :first_credential => "user",
81
+ :second_credential => "password")
82
+ end
83
+
84
+ it_should_behave_like 'a download repository'
85
+ end
86
+
87
+ context 'with a download repository with just a user' do
88
+ before(:each) do
89
+ @repository = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
90
+ :repo_type => :download,
91
+ :url => "http://a.site/foo/bar/baz",
92
+ :first_credential => "user")
93
+ end
94
+
95
+ it_should_behave_like 'a download repository'
96
+ end
97
+
98
+ context 'with a weird download repository' do
99
+ before(:each) do
100
+ @repository = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
101
+ :repo_type => :download,
102
+ :url => "urn:a.site:stuff")
103
+ end
104
+
105
+ it_should_behave_like 'a download repository'
106
+ end
107
+
108
+ context 'with a malicious download repository' do
109
+ before(:each) do
110
+ @repository = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
111
+ :repo_type => :download,
112
+ :url => "http://foo.bar.baz.quux/%20CBLAH",
113
+ :first_credential => "foo:b/ar",
114
+ :second_credential => "foo@bar")
115
+ end
116
+
117
+ it_should_behave_like 'a download repository'
118
+ end
119
+
120
+ context 'with a download repository that includes a query' do
121
+ before(:each) do
122
+ @repository = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
123
+ :repo_type => :download,
124
+ :url => "http://foo.bar.baz.quux/stuff?q=bar")
125
+ end
126
+
127
+ it_should_behave_like 'a download repository'
128
+ end
129
+
130
+ end
@@ -0,0 +1,106 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'multi_dir_spec_helper'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'scraper_helper'))
26
+
27
+ describe RightScraper::Retrievers::Download do
28
+ context 'in a multiple directory situation with a resources_path set' do
29
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
30
+
31
+ include RightScraper::ScraperHelper
32
+ include RightScraper::SpecHelpers
33
+
34
+ before(:each) do
35
+ @helper = RightScraper::MultiDirectorySpecHelper.new
36
+ @repo = @helper.repo
37
+ end
38
+
39
+ after(:each) do
40
+ @helper.close unless @helper.nil?
41
+ @helper = nil
42
+ end
43
+
44
+ context 'given a download repository' do
45
+ before(:each) do
46
+ @retriever = @repo.retriever(:max_bytes => 1024**2, :max_seconds => 20, :basedir => @helper.download_repo_path)
47
+ @retriever.retrieve
48
+ @scraper = RightScraper::Scrapers::Base.scraper(:kind => :cookbook,
49
+ :ignorable_paths => @retriever.ignorable_paths,
50
+ :repo_dir => @retriever.repo_dir,
51
+ :repository => @retriever.repository)
52
+
53
+ @download_file = @helper.download_file
54
+ end
55
+
56
+ it 'should return two cookbooks' do
57
+ @scraper.next_resource.should_not == nil
58
+ @scraper.next_resource.should_not == nil
59
+ @scraper.next_resource.should == nil
60
+ end
61
+
62
+ it 'should scrape' do
63
+ @helper.check_resource(@scraper.next_resource, @download_file, @repo, "subdir1")
64
+ @helper.check_resource(@scraper.next_resource, @download_file, @repo, "subdir2")
65
+ end
66
+ end
67
+
68
+ it 'should scrape a gzipped tarball' do
69
+ @download_file = @helper.download_file
70
+ res, status = exec("gzip -c #{@download_file} > #{@download_file}.gz")
71
+ raise "Failed to gzip tarball: #{res}" unless status.success?
72
+ begin
73
+ @repo.url += ".gz"
74
+ @retriever = @repo.retriever(:max_bytes => 1024**2, :max_seconds => 20, :basedir => @helper.download_repo_path)
75
+ @retriever.retrieve
76
+ @scraper = RightScraper::Scrapers::Base.scraper(:kind => :cookbook,
77
+ :ignorable_paths => @retriever.ignorable_paths,
78
+ :repo_dir => @retriever.repo_dir,
79
+ :repository => @retriever.repository)
80
+ @helper.check_resource(@scraper.next_resource, @download_file + ".gz", @repo, "subdir1")
81
+ @helper.check_resource(@scraper.next_resource, @download_file + ".gz", @repo, "subdir2")
82
+ ensure
83
+ File.unlink(@download_file + ".gz")
84
+ end
85
+ end
86
+
87
+ it 'should scrape a bzipped tarball' do
88
+ @download_file = @helper.download_file
89
+ res, status = exec("bzip2 -c #{@download_file} > #{@download_file}.bz2")
90
+ raise "Failed to bzip tarball: #{res}" unless status.success?
91
+ begin
92
+ @repo.url += ".bz2"
93
+ @retriever = @repo.retriever(:max_bytes => 1024**2, :max_seconds => 20, :basedir => @helper.download_repo_path)
94
+ @retriever.retrieve
95
+ @scraper = RightScraper::Scrapers::Base.scraper(:kind => :cookbook,
96
+ :ignorable_paths => @retriever.ignorable_paths,
97
+ :repo_dir => @retriever.repo_dir,
98
+ :repository => @retriever.repository)
99
+ @helper.check_resource(@scraper.next_resource, @download_file + ".bz2", @repo, "subdir1")
100
+ @helper.check_resource(@scraper.next_resource, @download_file + ".bz2", @repo, "subdir2")
101
+ ensure
102
+ File.unlink(@download_file + ".bz2")
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,40 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), 'download_retriever_spec_helper'))
25
+
26
+ module RightScraper
27
+ class MultiDirectorySpecHelper < DownloadRetrieverSpecHelper
28
+ def make_cookbooks
29
+ super
30
+ create_cookbook(File.join(download_repo_path, 'subdir1'), repo_content)
31
+ create_cookbook(File.join(download_repo_path, 'subdir2'), repo_content)
32
+ end
33
+
34
+ def repo
35
+ r = super
36
+ r.resources_path = ['subdir1', 'subdir2']
37
+ r
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,166 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
24
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'cookbook_helper'))
25
+
26
+ describe RightScraper::Resources::Cookbook do
27
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
28
+
29
+ include RightScraper::CookbookHelper
30
+
31
+ shared_examples_for 'a git repository' do
32
+ it_should_behave_like 'a generic repository'
33
+ end
34
+
35
+ context 'with an invalid git repository' do
36
+ before(:each) do
37
+ @repository = RightScraper::Repositories::Git.from_hash(:display_name => 'test repo',
38
+ :repo_type => :git,
39
+ :url => "http://a.site/foo/bar/baz")
40
+ end
41
+
42
+ it_should_behave_like 'a git repository'
43
+
44
+ it 'should fail to scrape' do
45
+ lambda {
46
+ begin
47
+ @tmpdir = Dir.mktmpdir
48
+ retriever = @repository.retriever(:basedir => @tmpdir)
49
+ retriever.retrieve
50
+ ensure
51
+ FileUtils.remove_entry_secure(@tmpdir)
52
+ end
53
+ }.should raise_exception(Git::GitExecuteError)
54
+ end
55
+ end
56
+
57
+ context 'with a git repository with a credential that requires a password' do
58
+ before(:each) do
59
+ passwd_key = File.open(File.join(File.dirname(__FILE__), 'password_key')).read
60
+ @repository = RightScraper::Repositories::Git.from_hash(
61
+ :display_name => 'test repo',
62
+ :repo_type => :git,
63
+ :url => "http://a.site/foo/bar/baz",
64
+ :first_credential => passwd_key)
65
+ end
66
+
67
+ it_should_behave_like 'a git repository'
68
+
69
+ it 'should close the connection to the agent' do
70
+ oldpid = ENV['SSH_AGENT_PID']
71
+ lambda {
72
+ begin
73
+ @tmpdir = Dir.mktmpdir
74
+ retriever = @repository.retriever(:basedir => @tmpdir)
75
+ retriever.retrieve
76
+ ensure
77
+ FileUtils.remove_entry_secure(@tmpdir)
78
+ end
79
+ }.should raise_exception(ProcessWatcher::NonzeroExitCode)
80
+ ENV['SSH_AGENT_PID'].should == oldpid
81
+ end
82
+ end
83
+
84
+ context 'with an invalid git repository with a real credential' do
85
+ before(:each) do
86
+ passwd_key = File.open(File.join(File.dirname(__FILE__), 'demokey')).read
87
+ @repository = RightScraper::Repositories::Git.from_hash(
88
+ :display_name => 'test repo',
89
+ :repo_type => :git,
90
+ :url => "http://example.example/foo/bar/baz",
91
+ :first_credential => passwd_key)
92
+ end
93
+
94
+ it_should_behave_like 'a git repository'
95
+
96
+ it 'should close the connection to the agent' do
97
+ oldpid = ENV['SSH_AGENT_PID']
98
+ lambda {
99
+ begin
100
+ @tmpdir = Dir.mktmpdir
101
+ retriever = @repository.retriever(:basedir => @tmpdir)
102
+ retriever.retrieve
103
+ ensure
104
+ FileUtils.remove_entry_secure(@tmpdir)
105
+ end
106
+ }.should raise_exception(Git::GitExecuteError)
107
+ ENV['SSH_AGENT_PID'].should == oldpid
108
+ end
109
+ end
110
+
111
+ context 'with a git repository' do
112
+ before(:each) do
113
+ @repository = RightScraper::Repositories::Git.from_hash(
114
+ :display_name => 'test repo',
115
+ :repo_type => :git,
116
+ :url => "http://a.site/foo/bar/baz",
117
+ :first_credential => "a-key")
118
+ end
119
+
120
+ it_should_behave_like 'a git repository'
121
+
122
+ it 'should have a tag' do
123
+ @repository.tag.should == "master"
124
+ end
125
+
126
+ it 'should have a cookbook hash' do
127
+ repo_hash = Digest::SHA1.hexdigest("1\000git\000http://a.site/foo/bar/baz\000master")
128
+ example_cookbook(@repository).resource_hash.should ==
129
+ Digest::SHA1.hexdigest("1\000#{repo_hash}\000")
130
+ end
131
+
132
+ it 'should have a cookbook hash invariant under credential changes' do
133
+ old_hash = example_cookbook(@repository).resource_hash
134
+ @repository.first_credential = "b-key"
135
+ example_cookbook(@repository).resource_hash.should == old_hash
136
+ end
137
+
138
+ it 'should have a cookbook hash that varies when the tag changes' do
139
+ old_hash = example_cookbook(@repository).resource_hash
140
+ @repository.tag = "tag"
141
+ example_cookbook(@repository).resource_hash.should_not == old_hash
142
+ end
143
+
144
+ it 'should have a cookbook hash that varies when the position changes' do
145
+ example_cookbook(@repository, "foo").resource_hash.should_not ==
146
+ example_cookbook(@repository, "bar").resource_hash
147
+ end
148
+ end
149
+ context 'with a git repository with a tag' do
150
+ before(:each) do
151
+ @repository = RightScraper::Repositories::Git.from_hash(
152
+ :display_name => 'test repo',
153
+ :repo_type => :git,
154
+ :url => "http://a.site/foo/bar/baz",
155
+ :tag => "DEADBEEF",
156
+ :first_credential => "a-key")
157
+ end
158
+
159
+ it_should_behave_like 'a git repository'
160
+
161
+ it 'should have a tag' do
162
+ @repository.tag.should == "DEADBEEF"
163
+ end
164
+ end
165
+
166
+ end
data/spec/git/demokey ADDED
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEoQIBAAKCAQEAxJsM8sZ6++Nky/ogLEYhKtKivB37sPB9M6Un0z6PkIRgUsGd
3
+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GAfKsWRnCKymzPrLfUdE8bb96Q
19
+ tDKokIrdh3iQc6toqDHwGlzHyRatLsgiv4vlBj/MUcQkJw/r/fzYlm5gP6CmN/rk
20
+ 6tlyEy3ZsteYe35QCpEYwgkH+2w9NJ3uOaZXFoPrOyObiRmE2A+eRHXIj7X97MLm
21
+ xovmStXk2962DtrnZCMCgYEAqRFjE1ckxXtm+9w7OjfZ6A5g9wQ3QSAzJ/Voe+yh
22
+ amoTYFS0DZ0lAZOcPeFVHTqJlt4VAvh0W74q8lNMjsckEMxw6Rr9TirswdqUGn07
23
+ ysXhCTHLepjw/kL3NPbjVFguHORI54paJooAuK5xqbCnzkaNuYncNRT9DEShvqXQ
24
+ 288CgYA+2HcMnscZOBF7DStMxEgmJuez9XE04ke0Mbzs1Igp001jllJExOtI/4pn
25
+ uVfahf3ds/n3YQu0wHLe2utKckE4DCd3zMKTwz32pGodXzSFwhNteeEutefHLtsH
26
+ 2IPpEtDXfDbBUJGYFLKyUHswZ9glKffhs31X5jb77BMbScNEQw==
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxJsM8sZ6++Nky/ogLEYhKtKivB37sPB9M6Un0z6PkIRgUsGdntMJqP1U6820jH+n1/lOH/MnlUsvzoo8DnOdbe9kGOHBmtWmNcjqacZUn9DbpbjvlI7RUUmZ5OBKn8Pjt2qbSXnnci9Q5j5Rgh6DR8A70S04FIUP8AGpCIO23BhA928CiM18zN5mBvzET7L2DYiNhJJFsFWMbN13CdukTjNVNLETEusNVUU09G1NxX4esKky7tHh1c9APFvu98KjYOHkv1o7dB7T4dO3KaKCNWINCHeeoE+QmAkhAZwI72ijRkPxH+QMisMsHucPFvgOVVObxHWu9hRlNWIOodANHQ== grahamhughes@Graham-Hughess-Computer.local
@@ -0,0 +1,30 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ Proc-Type: 4,ENCRYPTED
3
+ DEK-Info: DES-ED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WGgtJ5TTuBLM5KmQ== grahamhughes@kyuzo.local
@@ -0,0 +1,110 @@
1
+ #--
2
+ # Copyright: Copyright (c) 2010-2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'right_scraper', 'repositories', 'mock'))
26
+
27
+ describe RightScraper::Repositories::Git do
28
+ include RightScraper::SpecHelpers::DevelopmentModeEnvironment
29
+
30
+ shared_examples_for 'git repository for hashing' do
31
+ it 'should have the same repository hash with or without credentials' do
32
+ initial_hash = @repo.repository_hash
33
+ @repo.first_credential = nil
34
+ @repo.repository_hash.should == initial_hash
35
+ end
36
+
37
+ it 'should have the same checkout hash with or without credentials' do
38
+ initial_hash = @repo.checkout_hash
39
+ @repo.first_credential = nil
40
+ @repo.checkout_hash.should == initial_hash
41
+ end
42
+
43
+ it 'should have a different checkout hash from repository hash' do
44
+ @repo.repository_hash.should_not == @repo.checkout_hash
45
+ end
46
+
47
+ it 'should have the same repository hash regardless of tag' do
48
+ initial_hash = @repo.repository_hash
49
+ @repo.tag = 'bar'
50
+ @repo.repository_hash.should == initial_hash
51
+ end
52
+
53
+ it 'should have different checkout hashes as tags change' do
54
+ initial_hash = @repo.checkout_hash
55
+ @repo.tag = 'bar'
56
+ @repo.checkout_hash.should_not == initial_hash
57
+ end
58
+ end
59
+
60
+ context 'with an HTTP scheme' do
61
+ before(:each) do
62
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
63
+ :repo_type => :git,
64
+ :url => "http://foo.bar.baz.quux/%20CBLAH",
65
+ :tag => 'foo',
66
+ :first_credential => "foo:b/ar")
67
+ end
68
+
69
+ it 'should have a checkout hash' do
70
+ @repo.checkout_hash.should ==
71
+ Digest::SHA1.hexdigest("1\000git\000http://foo.bar.baz.quux/%20CBLAH\000foo")
72
+ end
73
+
74
+ it_should_behave_like 'git repository for hashing'
75
+ end
76
+
77
+ context 'with a git scheme' do
78
+ before(:each) do
79
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
80
+ :repo_type => :git,
81
+ :url => "git://foo.bar.baz.quux/%20CBLAH",
82
+ :tag => 'foo',
83
+ :first_credential => "foo:b/ar")
84
+ end
85
+
86
+ it 'should have a checkout hash' do
87
+ @repo.checkout_hash.should ==
88
+ Digest::SHA1.hexdigest("1\000git\000git://foo.bar.baz.quux/%20CBLAH\000foo")
89
+ end
90
+
91
+ it_should_behave_like 'git repository for hashing'
92
+ end
93
+
94
+ context 'with an ssh-type scheme' do
95
+ before(:each) do
96
+ @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
97
+ :repo_type => :git,
98
+ :url => "foo@bar.baz.quux:/%20CBLAH",
99
+ :tag => 'foo',
100
+ :first_credential => "foo:b/ar")
101
+ end
102
+
103
+ it 'should have a checkout hash' do
104
+ @repo.checkout_hash.should ==
105
+ Digest::SHA1.hexdigest("1\000git\000foo@bar.baz.quux:/%20CBLAH\000foo")
106
+ end
107
+
108
+ it_should_behave_like 'git repository for hashing'
109
+ end
110
+ end