Skip to content

added spec test for username validation #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions spec/unit/puppet/type/database_user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'puppet'
require 'puppet/type/database_user'
describe Puppet::Type.type(:database_user) do

let :params do
{
:password_hash => 'pass',
}
end

it 'should require a name' do
expect {
Puppet::Type.type(:database_user).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end

context 'with a valid user@hostname' do
before :each do
params.merge!({ :name => "foo@localhost" })
end

it 'should accept a user name' do
resource = Puppet::Type.type(:database_user).new(params)
resource[:name].should == 'foo@localhost'
end

it 'should accept a password' do
resource = Puppet::Type.type(:database_user).new(params)
resource[:password_hash] = 'foo'
resource[:password_hash].should == 'foo'
end

end

context 'with a long username' do
before :each do
params.merge!({ :name => "12345678901234567@localhost" })
end

it 'should fail with a long user name' do
expect {
resource = Puppet::Type.type(:database_user).new(params)
}.to raise_error(/MySQL usernames are limited to a maximum of 16 characters/)
end
end

context 'with a valid user@' do
before :each do
params.merge!({ :name => "foo@" })
end

it 'should accept a user name' do
resource = Puppet::Type.type(:database_user).new(params)
resource[:name].should == 'foo@'
end
end

context 'with an invalid user' do
before :each do
params.merge!({ :name => "foo" })
end

it 'should fail without a hostname' do
expect {
resource = Puppet::Type.type(:database_user).new(params)
}.to raise_error(/Invalid database user foo/)
end
end

end
88 changes: 64 additions & 24 deletions spec/unit/puppet/type/mysql_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,69 @@
require 'puppet/type/mysql_user'
describe Puppet::Type.type(:mysql_user) do

before :each do
@user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass')
end

it 'should accept a user name' do
@user[:name].should == 'foo@localhost'
end

it 'should fail with a long user name' do
expect {
Puppet::Type.type(:mysql_user).new({:name => '12345678901234567@localhost', :password_hash => 'pass'})
}.to raise_error /MySQL usernames are limited to a maximum of 16 characters/
end

it 'should accept a password' do
@user[:password_hash] = 'foo'
@user[:password_hash].should == 'foo'
end

it 'should require a name' do
expect {
Puppet::Type.type(:mysql_user).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
let :params do
{
:password_hash => 'pass',
}
end

it 'should require a name' do
expect {
Puppet::Type.type(:mysql_user).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end

context 'with a valid user@hostname' do
before :each do
params.merge!({ :name => "foo@localhost" })
end

it 'should accept a user name' do
resource = Puppet::Type.type(:mysql_user).new(params)
resource[:name].should == 'foo@localhost'
end

it 'should accept a password' do
resource = Puppet::Type.type(:mysql_user).new(params)
resource[:password_hash] = 'foo'
resource[:password_hash].should == 'foo'
end

end

context 'with a long username' do
before :each do
params.merge!({ :name => "12345678901234567@localhost" })
end

it 'should fail with a long user name' do
expect {
resource = Puppet::Type.type(:mysql_user).new(params)
}.to raise_error(/MySQL usernames are limited to a maximum of 16 characters/)
end
end

context 'with a valid user@' do
before :each do
params.merge!({ :name => "foo@" })
end

it 'should accept a user name' do
resource = Puppet::Type.type(:mysql_user).new(params)
resource[:name].should == 'foo@'
end
end

context 'with an invalid user' do
before :each do
params.merge!({ :name => "foo" })
end

it 'should fail without a hostname' do
expect {
resource = Puppet::Type.type(:mysql_user).new(params)
}.to raise_error(/Invalid database user foo/)
end
end

end