diff --git a/lib/common_helper.rb b/lib/common_helper.rb
index ef2bb2c0..7a404816 100644
--- a/lib/common_helper.rb
+++ b/lib/common_helper.rb
@@ -66,7 +66,7 @@ def get_equal_string_end(stringarray = [""])
break
end
end
- if looping == false or (counter * -1 ) >= base.length
+ if looping == false or (counter * -1 ) > base.length
break
end
already_found = "#{character if character}#{already_found}"
diff --git a/lib/wpscan/modules/wp_usernames.rb b/lib/wpscan/modules/wp_usernames.rb
index db0b9536..a2f35fa0 100644
--- a/lib/wpscan/modules/wp_usernames.rb
+++ b/lib/wpscan/modules/wp_usernames.rb
@@ -79,8 +79,14 @@ module WpUsernames
end
def remove_junk_from_nickname(usernames)
+ unless usernames.kind_of? Array
+ raise("Need an array as input")
+ end
nicknames = []
usernames.each do |u|
+ unless u.kind_of? WpUser
+ raise("Items must be of type WpUser")
+ end
nickname = u.nickname
unless nickname == "empty"
nicknames << nickname
diff --git a/spec/lib/wpscan/modules/wp_usernames_spec.rb b/spec/lib/wpscan/modules/wp_usernames_spec.rb
index ce319535..cdae154e 100644
--- a/spec/lib/wpscan/modules/wp_usernames_spec.rb
+++ b/spec/lib/wpscan/modules/wp_usernames_spec.rb
@@ -80,4 +80,161 @@ shared_examples_for "WpUsernames" do
end
end
+ describe "#get_nickname_from_url" do
+ after :each do
+ url = "http://example.localhost/"
+ stub_request(:get, url).to_return(:status => @status, :body => @content)
+ username = @module.get_nickname_from_url(url)
+ username.should === @expected
+ end
+
+ it "should return nil" do
+ @status = 200
+ @content = ""
+ @expected = nil
+ end
+
+ it "should return nil" do
+ @status = 400
+ @content = ""
+ @expected = nil
+ end
+
+ it "should return admin" do
+ @status = 200
+ @content = "
admin"
+ @expected = "admin"
+ end
+
+ it "should return nil" do
+ @status = 201
+ @content = "admin"
+ @expected = nil
+ end
+ end
+
+ describe "#get_nickname_from_response" do
+ after :each do
+ url = "http://example.localhost/"
+ stub_request(:get, url).to_return(:status => @status, :body => @content)
+ resp = Browser.instance.get(url)
+ username = @module.get_nickname_from_response(resp)
+ username.should === @expected
+ end
+
+ it "should return nil" do
+ @status = 200
+ @content = ""
+ @expected = nil
+ end
+
+ it "should return nil" do
+ @status = 400
+ @content = ""
+ @expected = nil
+ end
+
+ it "should return admin" do
+ @status = 200
+ @content = "admin"
+ @expected = "admin"
+ end
+
+ it "should return nil" do
+ @status = 201
+ @content = "admin"
+ @expected = nil
+ end
+ end
+
+ describe "#extract_nickname_from_body" do
+ after :each do
+ result = @module.extract_nickname_from_body(@body)
+ result.should === @expected
+ end
+
+ it "should return admin" do
+ @body = "admin"
+ @expected = "admin"
+ end
+
+ it "should return nil" do
+ @body = "adm"
+ @expected = nil
+ end
+
+ it "should return nil" do
+ @body = "admin"
+ @expected = nil
+ end
+
+ it "should return admin | " do
+ @body = "admin | "
+ @expected = "admin | "
+ end
+
+ it "should return an empty string" do
+ @body = ""
+ @expected = ""
+ end
+ end
+
+ describe "#remove_junk_from_nickname" do
+ it "should throw an exception" do
+ @input = nil
+ expect { @module.remove_junk_from_nickname(@input) }.to raise_error(RuntimeError, "Need an array as input")
+ end
+
+ it "should not throw an exception" do
+ @input = []
+ expect { @module.remove_junk_from_nickname(@input) }.to_not raise_error
+ end
+
+ it "should throw an exception" do
+ @input = [WpOptions.new]
+ expect { @module.remove_junk_from_nickname(@input) }.to raise_error(RuntimeError, "Items must be of type WpUser")
+ end
+ end
+
+ describe "#remove_junk_from_nickname" do
+ after :each do
+ result = @module.remove_junk_from_nickname(@input)
+ result.eql?(@expected).should === true
+ end
+
+ it "should return an empty array" do
+ @input = []
+ @expected = @input
+ end
+
+ it "should return input object" do
+ @input = [WpUser.new(nil, nil, nil)]
+ @expected = @input
+ end
+
+ it "should return input object" do
+ @input = [WpUser.new("", "", "")]
+ @expected = @input
+ end
+
+ it "should remove asdf" do
+ @input = [WpUser.new(nil, nil, "lkjh asdf"), WpUser.new(nil, nil, "ijrjd asdf")]
+ @expected = [WpUser.new(nil, nil, "lkjh"), WpUser.new(nil, nil, "ijrjd")]
+ end
+
+ it "should return unmodified input object" do
+ @input = [WpUser.new(nil, nil, "lkjh asdfa"), WpUser.new(nil, nil, "ijrjd asdf")]
+ @expected = @input
+ end
+
+ it "should return input object" do
+ @input = [WpUser.new(nil, nil, "lkjh asdf")]
+ @expected = @input
+ end
+
+ it "should return lkhj asdf" do
+ @input = [WpUser.new(nil, nil, "lkhj asdf"), WpUser.new(nil, nil, "lkhj asdf")]
+ @expected = [WpUser.new(nil, nil, ""), WpUser.new(nil, nil, "")]
+ end
+ end
end