right_scraper 3.2.6 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/lib/right_scraper.rb +16 -34
  3. data/lib/right_scraper/builders.rb +32 -0
  4. data/lib/right_scraper/builders/base.rb +19 -20
  5. data/lib/right_scraper/builders/filesystem.rb +8 -6
  6. data/lib/right_scraper/builders/union.rb +4 -1
  7. data/lib/right_scraper/loggers.rb +31 -0
  8. data/lib/right_scraper/loggers/base.rb +113 -0
  9. data/lib/right_scraper/loggers/default.rb +98 -0
  10. data/lib/right_scraper/{scraper.rb → main.rb} +53 -9
  11. data/lib/right_scraper/processes.rb +33 -0
  12. data/lib/right_scraper/processes/shell.rb +227 -0
  13. data/lib/right_scraper/processes/{ssh.rb → ssh_agent.rb} +4 -0
  14. data/lib/right_scraper/processes/svn_client.rb +117 -0
  15. data/lib/right_scraper/processes/warden.rb +358 -0
  16. data/lib/right_scraper/registered_base.rb +154 -0
  17. data/lib/right_scraper/repositories.rb +33 -0
  18. data/lib/right_scraper/repositories/base.rb +271 -232
  19. data/lib/right_scraper/repositories/download.rb +8 -6
  20. data/lib/right_scraper/repositories/git.rb +8 -9
  21. data/lib/right_scraper/repositories/svn.rb +8 -8
  22. data/lib/right_scraper/resources.rb +32 -0
  23. data/lib/right_scraper/resources/base.rb +5 -1
  24. data/lib/right_scraper/resources/cookbook.rb +34 -27
  25. data/lib/right_scraper/resources/workflow.rb +27 -28
  26. data/lib/right_scraper/retrievers.rb +34 -0
  27. data/lib/right_scraper/retrievers/base.rb +80 -84
  28. data/lib/right_scraper/retrievers/checkout_base.rb +178 -0
  29. data/lib/right_scraper/retrievers/download.rb +125 -117
  30. data/lib/right_scraper/retrievers/git.rb +377 -223
  31. data/lib/right_scraper/retrievers/svn.rb +102 -62
  32. data/lib/right_scraper/scanners.rb +37 -0
  33. data/lib/right_scraper/scanners/base.rb +77 -80
  34. data/lib/right_scraper/scanners/cookbook_manifest.rb +31 -30
  35. data/lib/right_scraper/scanners/cookbook_metadata.rb +380 -35
  36. data/lib/right_scraper/scanners/cookbook_s3_upload.rb +56 -53
  37. data/lib/right_scraper/scanners/union.rb +61 -58
  38. data/lib/right_scraper/scanners/workflow_manifest.rb +55 -54
  39. data/lib/right_scraper/scanners/workflow_metadata.rb +41 -39
  40. data/lib/right_scraper/scanners/workflow_s3_upload.rb +59 -55
  41. data/lib/right_scraper/scrapers.rb +32 -0
  42. data/lib/right_scraper/scrapers/base.rb +217 -205
  43. data/lib/right_scraper/scrapers/cookbook.rb +42 -40
  44. data/lib/right_scraper/scrapers/workflow.rb +57 -58
  45. data/lib/right_scraper/version.rb +3 -0
  46. data/right_scraper.gemspec +12 -16
  47. metadata +57 -163
  48. data/Gemfile +0 -15
  49. data/Rakefile +0 -89
  50. data/lib/right_scraper/logger.rb +0 -107
  51. data/lib/right_scraper/loggers/noisy.rb +0 -85
  52. data/lib/right_scraper/repositories/mock.rb +0 -70
  53. data/lib/right_scraper/retrievers/checkout.rb +0 -79
  54. data/lib/right_scraper/scraper_logger.rb +0 -66
  55. data/lib/right_scraper/svn_client.rb +0 -164
  56. data/right_scraper.rconf +0 -13
  57. data/spec/builder_spec.rb +0 -50
  58. data/spec/cookbook_helper.rb +0 -73
  59. data/spec/cookbook_manifest_spec.rb +0 -93
  60. data/spec/cookbook_s3_upload_spec.rb +0 -159
  61. data/spec/download/download_retriever_spec.rb +0 -118
  62. data/spec/download/download_retriever_spec_helper.rb +0 -72
  63. data/spec/download/download_spec.rb +0 -128
  64. data/spec/download/multi_dir_spec.rb +0 -106
  65. data/spec/download/multi_dir_spec_helper.rb +0 -40
  66. data/spec/git/cookbook_spec.rb +0 -165
  67. data/spec/git/demokey +0 -27
  68. data/spec/git/demokey.pub +0 -1
  69. data/spec/git/password_key +0 -30
  70. data/spec/git/password_key.pub +0 -1
  71. data/spec/git/repository_spec.rb +0 -110
  72. data/spec/git/retriever_spec.rb +0 -553
  73. data/spec/git/retriever_spec_helper.rb +0 -112
  74. data/spec/git/scraper_spec.rb +0 -151
  75. data/spec/git/ssh_spec.rb +0 -174
  76. data/spec/git/url_spec.rb +0 -103
  77. data/spec/logger_spec.rb +0 -185
  78. data/spec/repository_spec.rb +0 -111
  79. data/spec/retriever_spec_helper.rb +0 -146
  80. data/spec/scanner_spec.rb +0 -61
  81. data/spec/scraper_helper.rb +0 -88
  82. data/spec/scraper_spec.rb +0 -147
  83. data/spec/spec_helper.rb +0 -185
  84. data/spec/svn/cookbook_spec.rb +0 -96
  85. data/spec/svn/multi_svn_spec.rb +0 -64
  86. data/spec/svn/multi_svn_spec_helper.rb +0 -40
  87. data/spec/svn/repository_spec.rb +0 -72
  88. data/spec/svn/retriever_spec.rb +0 -266
  89. data/spec/svn/scraper_spec.rb +0 -90
  90. data/spec/svn/svn_retriever_spec_helper.rb +0 -90
  91. data/spec/svn/url_spec.rb +0 -47
  92. data/spec/url_spec.rb +0 -164
@@ -1,112 +0,0 @@
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__), '..', 'retriever_spec_helper'))
26
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'scraper_helper'))
27
- require 'git'
28
-
29
- module Git
30
- class Lib
31
- def public_command(*args, &block)
32
- command(*args, &block)
33
- end
34
- end
35
- end
36
- module RightScraper
37
-
38
- # Git implementation of scraper spec helper
39
- # See parent class for methods headers comments
40
- class GitRetrieverSpecHelper < RetrieverSpecHelper
41
- def initialize
42
- super()
43
- FileUtils.mkdir(scraper_path)
44
- @git = Git.init(repo_path)
45
- end
46
-
47
- def repo
48
- RightScraper::Repositories::Base.from_hash(:display_name => "test git repo",
49
- :repo_type => :git,
50
- :url => repo_path)
51
- end
52
-
53
- def setup_cookbooks
54
- create_cookbook(repo_path, repo_content)
55
- commit_content(repo_path)
56
- end
57
-
58
- def setup_workflows
59
- create_workflow(repo_path, 'workflow', "sequence\na\nb", {})
60
- commit_content(repo_path)
61
- end
62
-
63
- def scraper_path
64
- File.join(@tmpdir, "scraper")
65
- end
66
-
67
- def commit_content(commit_message='commit')
68
- @git.add('.')
69
- @git.commit_all(commit_message)
70
- end
71
-
72
- def setup_branch(branch, new_content=nil)
73
- @git.branch(branch).checkout
74
- unless new_content.nil?
75
- create_file_layout(repo_path, new_content)
76
- @repo_content += new_content
77
- File.open(File.join(repo_path, 'metadata.json'), 'w') { |f|
78
- f.puts @repo_content.to_json
79
- }
80
- commit_content("Branch #{branch}")
81
- end
82
- end
83
-
84
- def setup_tag(tag)
85
- @git.add_tag(tag)
86
- end
87
-
88
- def delete_tag(tag)
89
- @git.lib.tag(['-d', tag])
90
- end
91
-
92
- def branch?(branch)
93
- Git.open(RightScraper::Retrievers::Base.repo_dir(scraper_path, repo)).branches.find {|b| b.name == branch}
94
- end
95
-
96
- def tag?(tag)
97
- Git.open(RightScraper::Retrievers::Base.repo_dir(scraper_path, repo)).tags.find {|t| t.name == tag}
98
- end
99
-
100
- def delete_branch(branch)
101
- @git.branch(branch).delete
102
- end
103
-
104
- def force_rebase(upstream, newbase)
105
- @git.lib.public_command("rebase", ["--onto", newbase, upstream])
106
- end
107
-
108
- def commit_id(index_from_last=0)
109
- @git.log.skip(1).first.sha
110
- end
111
- end
112
- end
@@ -1,151 +0,0 @@
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 'stringio'
25
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
26
- require File.expand_path(File.join(File.dirname(__FILE__), 'retriever_spec_helper'))
27
- require 'tmpdir'
28
- require 'flexmock'
29
-
30
- describe RightScraper::Scraper do
31
- include RightScraper::SpecHelpers::DevelopmentModeEnvironment
32
-
33
- include RightScraper::SharedExamples
34
-
35
- before(:each) do
36
- # ulimit is a /usr/bin file on the Mac but only a shell command in Linux.
37
- # invoking `sh -c ulimit -a` only returns the last token of output, in fact
38
- # invoking 'ulimit -a' programmatically seems to omit the 'open files' field
39
- # in which we are actually interested (whereas it is visible when run
40
- # manually in bash). the more specific 'ulimit -n' appears to work as
41
- # expected on mac and linux platforms *but* calling `sh -c ulimit -n`
42
- # returns a nonsensical 'unlimited' token in ruby so we have to jump the
43
- # additional hurdle of outputing to a temp file to get the right answer :@
44
- @tmpdir = Dir.mktmpdir
45
- output_file_path = File.join(@tmpdir, "ulimit_n.txt")
46
- system('sh', '-c', "ulimit -n>#{output_file_path}")
47
- ulimit = File.read(output_file_path).to_i
48
- File.delete(output_file_path)
49
- if ulimit < 512
50
- raise "Cannot run this spec because ulimit -n is only #{ulimit}; need 512 minimum!"
51
- end
52
- @stream = StringIO.new()
53
- @scraper = RightScraper::Scraper.new(:basedir => @tmpdir, :kind => :cookbook)
54
- end
55
-
56
- after(:each) do
57
- FileUtils.remove_entry_secure @tmpdir
58
- end
59
-
60
- it 'starts out successful' do
61
- @scraper.succeeded?.should be_true
62
- @scraper.errors.should == []
63
- end
64
-
65
- context 'given a Git repository' do
66
- before(:each) do
67
- @helper = RightScraper::GitRetrieverSpecHelper.new
68
- @helper.setup_cookbooks
69
- @repo = @helper.repo
70
- end
71
-
72
- after(:each) do
73
- @helper.close
74
- end
75
-
76
- it_should_behave_like "a normal repository"
77
-
78
- it 'should log correctly as it scrapes' do
79
- callback = flexmock("callback")
80
- callback.should_receive(:call).with(:begin, :retrieving, "from #{@repo}", nil).once.ordered
81
- callback.should_receive(:call).with(:begin, :initialize, String, nil).once.ordered
82
- callback.should_receive(:call).with(:commit, :initialize, String, nil).once.ordered
83
- callback.should_receive(:call).with(:begin, :checkout, "", nil).once.ordered
84
- callback.should_receive(:call).with(:begin, :cloning, "to #{RightScraper::Retrievers::Base.repo_dir(@tmpdir, @repo)}", nil).once.ordered
85
- callback.should_receive(:call).with(:commit, :cloning, "to #{RightScraper::Retrievers::Base.repo_dir(@tmpdir, @repo)}", nil).once.ordered
86
- callback.should_receive(:call).with(:begin, :fetch, "", nil).once.ordered
87
- callback.should_receive(:call).with(:commit, :fetch, "", nil).once.ordered
88
- callback.should_receive(:call).with(:begin, :checkout_revision, "", nil).once.ordered
89
- callback.should_receive(:call).with(:commit, :checkout_revision, "", nil).once.ordered
90
- callback.should_receive(:call).with(:commit, :checkout, "", nil).once.ordered
91
- callback.should_receive(:call).with(:commit, :retrieving, "from #{@repo}", nil).once.ordered
92
- callback.should_receive(:call).with(:begin, :scraping, String, nil).once.ordered
93
- callback.should_receive(:call).with(:begin, :finding_next_cookbook, String, nil).once.ordered
94
- callback.should_receive(:call).with(:begin, :reading_cookbook, String, nil).once.ordered
95
- callback.should_receive(:call).with(:begin, :scanning_filesystem, String, nil).once.ordered
96
- callback.should_receive(:call).with(:begin, :metadata_parsing, "", nil).once.ordered
97
- callback.should_receive(:call).with(:commit, :metadata_parsing, "", nil).once.ordered
98
- callback.should_receive(:call).with(:commit, :scanning_filesystem, String, nil).once.ordered
99
- callback.should_receive(:call).with(:commit, :reading_cookbook, String, nil).once.ordered
100
- callback.should_receive(:call).with(:commit, :finding_next_cookbook, String, nil).once.ordered
101
- callback.should_receive(:call).with(:begin, :next, "", nil).once.ordered
102
- callback.should_receive(:call).with(:begin, :searching, "", nil).once.ordered
103
- callback.should_receive(:call).with(:commit, :searching, "", nil).once.ordered
104
- callback.should_receive(:call).with(:commit, :next, "", nil).once.ordered
105
- callback.should_receive(:call).with(:begin, :next, "", nil).once.ordered
106
- callback.should_receive(:call).with(:commit, :next, "", nil).once.ordered
107
- callback.should_receive(:call).with(:commit, :scraping, String, nil).once.ordered
108
-
109
- @scraper.scrape(@repo) do |phase, operation, explanation, exception|
110
- callback.call(phase, operation, explanation, exception)
111
- end
112
- @scraper.succeeded?.should be_true
113
- end
114
-
115
- context 'with tag being an empty string' do
116
- before(:each) do
117
- @repo.tag = ""
118
- end
119
-
120
- it_should_behave_like "a normal repository"
121
- end
122
-
123
- context 'with some additional commits' do
124
- before(:each) do
125
- @helper.create_file_layout(@helper.repo_path, @helper.branch_content)
126
- @helper.commit_content("change to master")
127
- end
128
-
129
- context 'after a successful scraper run' do
130
- before(:each) do
131
- @scraper.scrape(@repo)
132
- @scraper.succeeded?.should be_true
133
- end
134
-
135
- context 'with some incompatible changes' do
136
- before(:each) do
137
- @helper.create_file_layout(@helper.repo_path, [{'other_branch_folder' => ['file7']}])
138
- @helper.commit_content("2nd change to master")
139
- @helper.force_rebase('master^', 'master^^')
140
- end
141
-
142
- it 'should still be successful' do
143
- @scraper.scrape(@repo)
144
- @scraper.errors.should == []
145
- @scraper.succeeded?.should be_true
146
- end
147
- end
148
- end
149
- end
150
- end
151
- end
data/spec/git/ssh_spec.rb DELETED
@@ -1,174 +0,0 @@
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
-
26
- describe RightScraper::Processes::SSHAgent do
27
- shared_examples_for 'a process that sets environment variables' do
28
- def setvar(name, value)
29
- if value.nil?
30
- ENV.delete name
31
- else
32
- ENV[name] = value
33
- end
34
- end
35
-
36
- it 'should set SSH_AUTH_SOCK' do
37
- oldsock = ENV['SSH_AUTH_SOCK']
38
- RightScraper::Processes::SSHAgent.with do |agent|
39
- ENV.should have_key('SSH_AUTH_SOCK')
40
- ENV['SSH_AUTH_SOCK'].should_not be_empty
41
- File.exists?(ENV['SSH_AUTH_SOCK']).should == true
42
- end
43
- ENV['SSH_AUTH_SOCK'].should == oldsock
44
- end
45
-
46
- it 'should set SSH_AGENT_PID' do
47
- oldpid = ENV['SSH_AUTH_PID']
48
- RightScraper::Processes::SSHAgent.with do |agent|
49
- ENV.should have_key('SSH_AGENT_PID')
50
- ENV['SSH_AGENT_PID'].should_not be_empty
51
- # This is a Unixism; sending signal 0 to a process tests whether
52
- # it exists, but has no effect on the process. I have no idea
53
- # how to express this on Windows.
54
- Process.kill(0, ENV['SSH_AGENT_PID'].to_i).should be_true
55
- end
56
- ENV['SSH_AUTH_PID'].should == oldpid
57
- end
58
-
59
- it 'should set SSH_ASKPASS' do
60
- oldpass = ENV['SSH_ASKPASS']
61
- RightScraper::Processes::SSHAgent.with do |agent|
62
- ENV.should have_key('SSH_ASKPASS')
63
- ENV['SSH_ASKPASS'].should_not be_empty
64
-
65
- script = File.expand_path(File.join(File.dirname(__FILE__), '..', '..',
66
- 'scripts', 'stub_ssh_askpass'))
67
- ENV['SSH_ASKPASS'].should == script
68
- end
69
- ENV['SSH_ASKPASS'].should == oldpass
70
- end
71
-
72
- it 'should set HOME' do
73
- oldhome = ENV['HOME']
74
- RightScraper::Processes::SSHAgent.with do |agent|
75
- ENV.should have_key('HOME')
76
- ENV['HOME'].should_not be_empty
77
- ENV['HOME'].should == "/dev/null"
78
- end
79
- ENV['HOME'].should == oldhome
80
- end
81
- end
82
-
83
- context 'with no relevant environment variables' do
84
- before(:each) do
85
- @display = ENV['DISPLAY']
86
- @askpass = ENV['SSH_ASKPASS']
87
- @sshauth = ENV['SSH_AUTH_SOCK']
88
- @agentpid = ENV['SSH_AGENT_PID']
89
- @home = ENV['HOME']
90
- ENV.delete 'DISPLAY'
91
- ENV.delete 'SSH_ASKPASS'
92
- ENV.delete 'SSH_AUTH_SOCK'
93
- ENV.delete 'SSH_AGENT_PID'
94
- ENV.delete 'HOME'
95
- end
96
-
97
- after(:each) do
98
- setvar 'DISPLAY', @display
99
- setvar 'SSH_ASKPASS', @askpass
100
- setvar 'SSH_AUTH_SOCK', @sshauth
101
- setvar 'SSH_AGENT_PID', @agentpid
102
- setvar 'HOME', @home
103
- end
104
-
105
- it_should_behave_like 'a process that sets environment variables'
106
- end
107
-
108
- context 'with relevant environment variables set' do
109
- before(:each) do
110
- @display = ENV['DISPLAY']
111
- @askpass = ENV['SSH_ASKPASS']
112
- @sshauth = ENV['SSH_AUTH_SOCK']
113
- @agentpid = ENV['SSH_AGENT_PID']
114
- @home = ENV['HOME']
115
- ENV['DISPLAY'] = "foo"
116
- ENV['SSH_ASKPASS'] = "bar"
117
- ENV['SSH_AUTH_SOCK'] = "baz"
118
- ENV['SSH_AGENT_PID'] = "quux"
119
- ENV['HOME'] = "fred"
120
- end
121
-
122
- after(:each) do
123
- setvar 'DISPLAY', @display
124
- setvar 'SSH_ASKPASS', @askpass
125
- setvar 'SSH_AUTH_SOCK', @sshauth
126
- setvar 'SSH_AGENT_PID', @agentpid
127
- setvar 'HOME', @home
128
- end
129
-
130
- it_should_behave_like 'a process that sets environment variables'
131
- end
132
-
133
- it 'should be able to load the demo key' do
134
- RightScraper::Processes::SSHAgent.with do |agent|
135
- demofile = File.expand_path(File.join(File.dirname(__FILE__), 'demokey'))
136
- File.chmod(0600, demofile)
137
- demofile = File.join(File.dirname(__FILE__), 'demokey')
138
- agent.add_keyfile(demofile)
139
- `ssh-add -l`.should == "2048 c7:66:87:fc:17:b5:2f:32:f2:c1:ed:40:a6:8d:17:44 #{demofile} (RSA)\n"
140
- `ssh-add -L`.should == <<FULLOUTPUT
141
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC18gNzaOwgJkHhUgPPNtCNp0H08ywzH1AquwSca19ZOedGnRWa673t4sXW0BeBn1wd8v0EulHRNwIyn0xJLsEStMOpo4A0qN+B2sM9gjBcY8nMOyUqy5s32pXncGfEwiRuiAxqz45VJqvL3CD8X5WxG300u/DNUbLZN0IT1aPn52Bo6gcGleZklxF1cccrbMelWfXE7KYKjD3/TfLdJeOlP9PJM8ijFHCsyWcKt5AH8bFkQ/xETPfqPzUIwvLDU7HpVDLZZ6JBi2rxhAAG+NhE3GMmY5i+vMB+g7CCfY200SFxzyjIcag05MGGko8Rv9bHnE3AYj9cxCULyDJyZm/T #{demofile}
142
- FULLOUTPUT
143
- end
144
- end
145
-
146
- it 'should fail on the passworded key' do
147
- pid = nil
148
- lambda {
149
- RightScraper::Processes::SSHAgent.with do |agent|
150
- pid = ENV['SSH_AGENT_PID'].to_i
151
- pid.should_not == 0
152
- demofile = File.expand_path(File.join(File.dirname(__FILE__), 'password_key'))
153
- File.chmod(0600, demofile)
154
- agent.add_keyfile(demofile) # will fail due to missing password
155
- end
156
- }.should raise_exception(::RightScraper::Processes::SSHAgent::SSHAgentError, /Attempted to use credentials that require passwords; bailing/)
157
-
158
- # the .with statement must ensure that the ssh-agent process terminates.
159
- lambda {
160
- Process.kill(0, pid)
161
- }.should raise_exception(Errno::ESRCH)
162
- end
163
-
164
- it 'should be able to load the demo key from memory' do
165
- RightScraper::Processes::SSHAgent.with do |agent|
166
- demofile = File.join(File.dirname(__FILE__), 'demokey')
167
- demodata = File.open(demofile).read
168
- agent.add_key(demodata)
169
- `ssh-add -l`.should =~ /^2048 c7:66:87:fc:17:b5:2f:32:f2:c1:ed:40:a6:8d:17:44 .*? \(RSA\)\n$/
170
- expected_pubkey = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC18gNzaOwgJkHhUgPPNtCNp0H08ywzH1AquwSca19ZOedGnRWa673t4sXW0BeBn1wd8v0EulHRNwIyn0xJLsEStMOpo4A0qN+B2sM9gjBcY8nMOyUqy5s32pXncGfEwiRuiAxqz45VJqvL3CD8X5WxG300u/DNUbLZN0IT1aPn52Bo6gcGleZklxF1cccrbMelWfXE7KYKjD3/TfLdJeOlP9PJM8ijFHCsyWcKt5AH8bFkQ/xETPfqPzUIwvLDU7HpVDLZZ6JBi2rxhAAG+NhE3GMmY5i+vMB+g7CCfY200SFxzyjIcag05MGGko8Rv9bHnE3AYj9cxCULyDJyZm/T'
171
- `ssh-add -L`.should =~ %r{^#{Regexp.escape(expected_pubkey)} .*\n$}
172
- end
173
- end
174
- end
data/spec/git/url_spec.rb DELETED
@@ -1,103 +0,0 @@
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
-
26
- describe RightScraper::Repositories::Base do
27
- def make_repo(url)
28
- @repo = RightScraper::Repositories::Base.from_hash(:display_name => 'test repo',
29
- :repo_type => :git,
30
- :url => url,
31
- :first_credential => "foo")
32
- end
33
- include RightScraper::SpecHelpers::ProductionModeEnvironment
34
-
35
- context 'with Git URIs' do
36
- it 'should not throw an error for http URIs' do
37
- lambda do
38
- make_repo "http://rightscale.com/%20CBLAH"
39
- end.should_not raise_exception
40
- end
41
- it 'should not throw an error for git URIs' do
42
- lambda do
43
- make_repo "git://rightscale.com/%20CBLAH"
44
- end.should_not raise_exception
45
- end
46
- it 'should not throw an error for absolute SCP URIs' do
47
- lambda do
48
- make_repo "git@rightscale.com:/%20CBLAH"
49
- end.should_not raise_exception
50
- end
51
- it 'should not throw an error for SCP URIs with dashes in the username' do
52
- lambda do
53
- make_repo "git-foo@rightscale.com:/%20CBLAH"
54
- end.should_not raise_exception
55
- end
56
- it 'should not throw an error for relative SCP URIs' do
57
- lambda do
58
- make_repo "git-foo@rightscale.com:%20CBLAH"
59
- end.should_not raise_exception
60
- end
61
- it 'should not throw an error for git+ssh URIs' do
62
- lambda do
63
- make_repo "git+ssh://rightscale.com/%20CBLAH"
64
- end.should_not raise_exception
65
- end
66
- it 'should not throw an error for ssh URIs' do
67
- lambda do
68
- make_repo "ssh://rightscale.com/%20CBLAH"
69
- end.should_not raise_exception
70
- end
71
- end
72
-
73
- context '#to_url' do
74
- it 'should correctly convert http URIs' do
75
- make_repo("http://rightscale.com/%20CBLAH").to_url.to_s.should ==
76
- "http://foo@rightscale.com/%20CBLAH"
77
- end
78
- it 'should correctly convert git URIs' do
79
- make_repo("git://rightscale.com/%20CBLAH").to_url.to_s.should ==
80
- "git://foo@rightscale.com/%20CBLAH"
81
- end
82
- it 'should correctly convert SCP URIs' do
83
- make_repo("git@rightscale.com:/%20CBLAH").to_url.to_s.should ==
84
- "ssh://git:foo@rightscale.com/%20CBLAH"
85
- end
86
- it 'should correctly convert SCP URIs with dashes in the username' do
87
- make_repo("git-foo@rightscale.com:/%20CBLAH").to_url.to_s.should ==
88
- "ssh://git-foo:foo@rightscale.com/%20CBLAH"
89
- end
90
- it 'should correctly convert relative SCP URIs' do
91
- make_repo("git-foo@rightscale.com:%20CBLAH").to_url.to_s.should ==
92
- "ssh://git-foo:foo@rightscale.com/%20CBLAH"
93
- end
94
- it 'should correctly convert git+ssh URIs' do
95
- make_repo("git+ssh://rightscale.com/%20CBLAH").to_url.to_s.should ==
96
- "git+ssh://foo@rightscale.com/%20CBLAH"
97
- end
98
- it 'should correctly convert ssh URIs' do
99
- make_repo("ssh://rightscale.com/%20CBLAH").to_url.to_s.should ==
100
- "ssh://foo@rightscale.com/%20CBLAH"
101
- end
102
- end
103
- end