Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 798f462

Browse files
committed
Improve test coverage
1 parent 517c0cf commit 798f462

5 files changed

+312
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../../../spec_helper'
4+
require 'wpxf/modules'
5+
6+
describe Wpxf::Auxiliary::MailMastaUnauthenticatedLocalFileInclusion do
7+
let(:subject) { described_class.new }
8+
9+
before :each, 'setup subject' do
10+
allow(subject).to receive(:check_plugin_version_from_readme)
11+
allow(subject).to receive(:emit_error)
12+
end
13+
14+
it 'should return a {Wpxf::Module}' do
15+
expect(subject).to be_a Wpxf::Module
16+
end
17+
18+
it 'should check the plugin is installed' do
19+
subject.check
20+
expect(subject).to have_received(:check_plugin_version_from_readme)
21+
.with('mail-masta')
22+
.exactly(1).times
23+
end
24+
25+
it 'should not require authentication' do
26+
expect(subject.requires_authentication).to be false
27+
end
28+
29+
it 'should configure a default remote file path' do
30+
expected = '/etc/passwd'
31+
expect(subject.default_remote_file_path).to eql expected
32+
end
33+
34+
it 'should configure the working directory' do
35+
expected = 'wp-content/plugins/mail-masta/inc/campaign'
36+
expect(subject.working_directory).to eql expected
37+
end
38+
39+
it 'should configure the downloader url' do
40+
url_pattern = %r{plugins/mail-masta/inc/campaign/count_of_send\.php$}
41+
expect(subject.downloader_url).to match(url_pattern)
42+
end
43+
44+
it 'should configure the request params' do
45+
subject.set_option_value('remote_file', 'test.php')
46+
expect(subject.download_request_params).to eql(pl: 'test.php')
47+
end
48+
49+
it 'should GET the download request' do
50+
expect(subject.download_request_method).to eql :get
51+
end
52+
end
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../../../spec_helper'
4+
require 'wpxf/modules'
5+
6+
describe Wpxf::Auxiliary::MembershipSimplifiedArbitraryFileDownload do
7+
let(:subject) { described_class.new }
8+
9+
before :each, 'setup subject' do
10+
allow(subject).to receive(:check_plugin_version_from_readme)
11+
allow(subject).to receive(:emit_error)
12+
end
13+
14+
it 'should return a {Wpxf::Module}' do
15+
expect(subject).to be_a Wpxf::Module
16+
end
17+
18+
it 'should check the change log to verify the version is < 1.59' do
19+
res_mock = Wpxf::Net::HttpResponse.new(nil)
20+
res_mock.code = 200
21+
res_mock.body = %(
22+
= Beta 1.58 =
23+
Release notes
24+
25+
= Beta 1.57 =
26+
Release Notes
27+
)
28+
29+
allow(subject).to receive(:execute_get_request).and_return(res_mock)
30+
expect(subject.check).to eql :vulnerable
31+
end
32+
33+
it 'should not require authentication' do
34+
expect(subject.requires_authentication).to be false
35+
end
36+
37+
it 'should configure a default remote file path' do
38+
expected = '..././..././..././wp-config.php'
39+
expect(subject.default_remote_file_path).to eql expected
40+
end
41+
42+
it 'should configure the working directory' do
43+
expected = 'wp-content/plugins/membership-simplified-for-oap-members-only'
44+
expect(subject.working_directory).to eql expected
45+
end
46+
47+
it 'should configure the downloader url' do
48+
url_pattern = %r{plugins/membership-simplified-for-oap-members-only/download\.php$}
49+
expect(subject.downloader_url).to match(url_pattern)
50+
end
51+
52+
it 'should configure the request params' do
53+
subject.set_option_value('remote_file', 'test.php')
54+
expect(subject.download_request_params).to eql('download_file' => 'test.php')
55+
end
56+
57+
it 'should GET the download request' do
58+
expect(subject.download_request_method).to eql :get
59+
end
60+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../../../spec_helper'
4+
require 'wpxf/modules'
5+
6+
describe Wpxf::Auxiliary::MemphisDocumentsLibraryArbitraryFileDownload do
7+
let(:subject) { described_class.new }
8+
9+
before :each, 'setup subject' do
10+
allow(subject).to receive(:check_plugin_version_from_readme)
11+
allow(subject).to receive(:emit_error)
12+
end
13+
14+
it 'should return a {Wpxf::Module}' do
15+
expect(subject).to be_a Wpxf::Module
16+
end
17+
18+
it 'should check the plugin is < 3.1.6' do
19+
subject.check
20+
expect(subject).to have_received(:check_plugin_version_from_readme)
21+
.with('memphis-documents-library', '3.1.6')
22+
.exactly(1).times
23+
end
24+
25+
it 'should not require authentication' do
26+
expect(subject.requires_authentication).to be false
27+
end
28+
29+
it 'should configure a default remote file path' do
30+
expected = '../../../wp-config.php'
31+
expect(subject.default_remote_file_path).to eql expected
32+
end
33+
34+
it 'should configure the working directory' do
35+
expected = 'wp-content/plugins/memphis-documents-library/'
36+
expect(subject.working_directory).to eql expected
37+
end
38+
39+
it 'should configure the downloader url' do
40+
expect(subject.downloader_url).to eql subject.full_uri
41+
end
42+
43+
it 'should configure the request params' do
44+
subject.set_option_value('remote_file', 'test.php')
45+
expect(subject.download_request_params).to eql('mdocs-img-preview' => 'test.php')
46+
end
47+
48+
it 'should GET the download request' do
49+
expect(subject.download_request_method).to eql :get
50+
end
51+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../../../spec_helper'
4+
require 'wpxf/modules'
5+
6+
describe Wpxf::Auxiliary::RecentBackupsArbitraryFileDownload do
7+
let(:subject) { described_class.new }
8+
9+
before :each, 'setup subject' do
10+
allow(subject).to receive(:check_plugin_version_from_readme)
11+
allow(subject).to receive(:emit_error)
12+
end
13+
14+
it 'should return a {Wpxf::Module}' do
15+
expect(subject).to be_a Wpxf::Module
16+
end
17+
18+
it 'should check the plugin is installed' do
19+
subject.check
20+
expect(subject).to have_received(:check_plugin_version_from_readme)
21+
.with('recent-backups')
22+
.exactly(1).times
23+
end
24+
25+
it 'should not require authentication' do
26+
expect(subject.requires_authentication).to be false
27+
end
28+
29+
it 'should configure a default remote file path' do
30+
expected = '../../../wp-config.php'
31+
expect(subject.default_remote_file_path).to eql expected
32+
end
33+
34+
it 'should configure the working directory' do
35+
expected = 'wp-content/plugins/recent-backups/'
36+
expect(subject.working_directory).to eql expected
37+
end
38+
39+
it 'should configure the downloader url' do
40+
expected = %r{wp-content/plugins/recent\-backups/download\-file\.php}
41+
expect(subject.downloader_url).to match expected
42+
end
43+
44+
it 'should configure the request params' do
45+
subject.set_option_value('remote_file', 'test.php')
46+
expect(subject.download_request_params).to eql('file_link' => 'test.php')
47+
end
48+
49+
it 'should GET the download request' do
50+
expect(subject.download_request_method).to eql :get
51+
end
52+
end
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../../../spec_helper'
4+
require 'wpxf/modules'
5+
6+
describe Wpxf::Auxiliary::SimpleDownloadMonitorFileDisclosure do
7+
let(:subject) { described_class.new }
8+
let(:downloaded_filename) { File.join(Dir.tmpdir, 'wpxf_unit_test') }
9+
let(:content_mock) do
10+
%(
11+
{
12+
"test": [
13+
{ "post_id": 1, "post_title": "test1" },
14+
{ "post_id": 2, "post_title": "test2" }
15+
]
16+
}
17+
)
18+
end
19+
20+
before :each, 'setup subject' do
21+
allow(subject).to receive(:check_plugin_version_from_readme)
22+
allow(subject).to receive(:emit_error)
23+
allow(subject).to receive(:emit_table)
24+
allow(subject).to receive(:downloaded_filename).and_return(downloaded_filename)
25+
end
26+
27+
after :each, 'delete tmp files' do
28+
FileUtils.rm_f downloaded_filename
29+
end
30+
31+
it 'should return a {Wpxf::Module}' do
32+
expect(subject).to be_a Wpxf::Module
33+
end
34+
35+
it 'should check the plugin < 3.2.9' do
36+
subject.check
37+
expect(subject).to have_received(:check_plugin_version_from_readme)
38+
.with('simple-download-monitor', '3.2.9')
39+
.exactly(1).times
40+
end
41+
42+
it 'should not register the remote file option' do
43+
expect(subject.register_remote_file_option?).to be false
44+
end
45+
46+
it 'should not require authentication' do
47+
expect(subject.requires_authentication).to be false
48+
end
49+
50+
it 'should configure the downloader url' do
51+
expect(subject.downloader_url).to eql subject.wordpress_url_admin_ajax
52+
end
53+
54+
it 'should configure the request params' do
55+
expect(subject.download_request_params).to eql('action' => 'sdm_tiny_get_post_ids')
56+
end
57+
58+
it 'should GET the download request' do
59+
expect(subject.download_request_method).to eql :get
60+
end
61+
62+
context 'if the response is valid JSON' do
63+
it 'should save the export as a CSV' do
64+
expect(subject.file_extension).to eql '.csv'
65+
subject.validate_content(content_mock)
66+
csv = CSV.parse(downloaded_filename)
67+
expect(csv).to_not be_nil
68+
end
69+
70+
it 'should emit the post ids and titles as a table' do
71+
expected_table = [
72+
{ post_id: 'Post ID', title: 'Title' },
73+
{ post_id: 1, title: 'test1' },
74+
{ post_id: 2, title: 'test2' }
75+
]
76+
77+
subject.validate_content(content_mock)
78+
expect(subject).to have_received(:emit_table)
79+
.with(expected_table)
80+
.exactly(1).times
81+
end
82+
end
83+
84+
context 'if the response is not valid JSON' do
85+
it 'should fail the validation process' do
86+
res = subject.validate_content('invalid json')
87+
expect(res).to be false
88+
end
89+
90+
it 'should emit an error' do
91+
subject.validate_content('invalid json')
92+
expect(subject).to have_received(:emit_error)
93+
.with('Could not parse the response')
94+
.exactly(1).times
95+
end
96+
end
97+
end

0 commit comments

Comments
 (0)