Skip to content

Commit 52d4d3e

Browse files
committed
Adjust approach to avoid CI hang
1 parent b3d47de commit 52d4d3e

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

app/controllers/core.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ def update_db_required?
3737
return false unless user_interaction? && local_db.outdated?
3838

3939
output('@notice', msg: 'It seems like you have not updated the database for some time.')
40-
response = Readline.readline('[?] Do you want to update now? [Y]es [N]o, default: [N] ', true)
40+
print '[?] Do you want to update now? [Y]es [N]o, default: [N]'
41+
$stdout.flush
42+
43+
response = $stdin.gets.to_s.strip
4144

4245
!!/^y/i.match?(response)
4346
end

spec/app/controllers/core_spec.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,19 @@
106106

107107
context 'when the db is outdated' do
108108
before do
109-
allow(core).to receive(:user_interaction?).and_return(true)
110109
expect(core.local_db).to receive(:outdated?).ordered.and_return(true)
111110
expect(core.formatter).to receive(:output).with('@notice', hash_including(:msg), 'core').ordered
111+
expect($stdout).to receive(:write).ordered # for the print()
112112
end
113113

114114
context 'when a positive answer' do
115-
before do
116-
expect(Readline).to receive(:readline).with('[?] Do you want to update now? [Y]es [N]o, default: [N] ',
117-
true).and_return('Yes')
118-
end
115+
before { expect(Readline).to receive(:readline).and_return('Yes').ordered }
119116

120117
its(:update_db_required?) { should eql true }
121118
end
122119

123120
context 'when a negative answer' do
124-
before do
125-
expect(Readline).to receive(:readline).with('[?] Do you want to update now? [Y]es [N]o, default: [N] ',
126-
true).and_return('No')
127-
end
121+
before { expect(Readline).to receive(:readline).and_return('no').ordered }
128122

129123
its(:update_db_required?) { should eql false }
130124
end
@@ -151,12 +145,12 @@
151145
context 'when --update' do
152146
before do
153147
expect(core.formatter).to receive(:output)
154-
.with('db_update_started', hash_including(verbose: nil), 'core').ordered
148+
.with('db_update_started', hash_including(verbose: nil), 'core').ordered
155149

156150
expect_any_instance_of(WPScan::DB::Updater).to receive(:update)
157151

158152
expect(core.formatter).to receive(:output)
159-
.with('db_update_finished', hash_including(verbose: nil), 'core').ordered
153+
.with('db_update_finished', hash_including(verbose: nil), 'core').ordered
160154
end
161155

162156
context 'when the --url is not supplied' do
@@ -200,16 +194,16 @@
200194
stub_request(:any, target_url)
201195

202196
expect(core.target).to receive(:homepage_res)
203-
.at_least(1)
204-
.and_return(Typhoeus::Response.new(effective_url: redirection, body: ''))
197+
.at_least(1)
198+
.and_return(Typhoeus::Response.new(effective_url: redirection, body: ''))
205199
end
206200

207201
context 'to the wp-admin/install.php' do
208202
let(:redirection) { "#{target_url}wp-admin/install.php" }
209203

210204
it 'calls the formatter with the correct parameters and exit' do
211205
expect(core.formatter).to receive(:output)
212-
.with('not_fully_configured', hash_including(url: redirection), 'core').ordered
206+
.with('not_fully_configured', hash_including(url: redirection), 'core').ordered
213207

214208
# TODO: Would be cool to be able to test the exit code
215209
expect { core.before_scan }.to raise_error(SystemExit)

0 commit comments

Comments
 (0)