-
Notifications
You must be signed in to change notification settings - Fork 21
(MODULES-2497) SQLSERVER - Create Automated Tests for sqlserver::login #150
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
Merged
cowofevil
merged 2 commits into
puppetlabs:master
from
phongdly:MODULES-2497/automated_test_for_sqlserver-login
Sep 15, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
require 'spec_helper_acceptance' | ||
require 'securerandom' | ||
|
||
host = find_only_one("sql_host") | ||
db_name = ("DB" + SecureRandom.hex(4)).upcase | ||
table_name = 'Tables_' + SecureRandom.hex(3) | ||
|
||
describe "Test sqlserver::login", :node => host do | ||
|
||
def ensure_manifest_apply(host, pp) | ||
apply_manifest_on(host, pp) do |r| | ||
expect(r.stderr).not_to match(/Error/i) | ||
end | ||
end | ||
|
||
#Return options for run_sql_query | ||
def run_sql_query_opts (user, passwd, query, expected_row_count) | ||
run_sql_query_opt = { | ||
:query => query, | ||
:sql_admin_user => user, | ||
:sql_admin_pass => passwd, | ||
:expected_row_count => expected_row_count, | ||
} | ||
end | ||
|
||
context "Start testing...", {:testrail => ['89118', '89119', '89120', '89121', '89122', '89123', '89124', '89125', '89540']} do | ||
|
||
before(:all) do | ||
# Create a database and a simple table to use for all the tests | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::database{'#{db_name}': | ||
} | ||
sqlserver_tsql{'testsqlserver_tsql': | ||
instance => 'MSSQLSERVER', | ||
database => '#{db_name}', | ||
command => "CREATE TABLE #{table_name} (id INT, name VARCHAR(20), email VARCHAR(20));", | ||
require => Sqlserver::Database['#{db_name}'], | ||
} | ||
MANIFEST | ||
ensure_manifest_apply(host, pp) | ||
end | ||
|
||
# Delete Database after all tests are done | ||
after(:all) do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::database{'#{db_name}': | ||
instance => 'MSSQLSERVER', | ||
ensure => 'absent', | ||
} | ||
MANIFEST | ||
#comment out the below line because of ticket MODULES-2554(delete database) | ||
#ensure_manifest_apply(host, pp) | ||
end | ||
|
||
# Generate different set of sqlserver login/password for each test | ||
before(:each) do | ||
@login_user = "Login" + SecureRandom.hex(4) | ||
@login_passwd = "Password" + SecureRandom.hex(5) | ||
end | ||
|
||
after(:each) do | ||
# delete recently created login after each test: | ||
#This test also cover test case C89540: Delete login | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::login{'#{@login_user}': | ||
instance => 'MSSQLSERVER', | ||
ensure => 'absent', | ||
} | ||
MANIFEST | ||
#comment out the below line because of ticket MODULES-2323(delete login) | ||
#ensure_manifest_apply(host, pp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
end | ||
|
||
it "Test Case C89118: create login with optional 'check_expiration'" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::login{'#{@login_user}': | ||
instance => 'MSSQLSERVER', | ||
login_type => 'SQL_LOGIN', | ||
password => '#{@login_passwd}', | ||
svrroles => {'sysadmin' => 1}, | ||
check_expiration => true, | ||
} | ||
|
||
MANIFEST | ||
ensure_manifest_apply(host, pp) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and able to access database '#{db_name}':" | ||
query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{table_name}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and has correct is_expiration_checked:" | ||
query = "SELECT name as LOGIN_NAME, is_expiration_checked | ||
FROM SYS.SQL_LOGINS | ||
WHERE is_expiration_checked = '1' | ||
AND name = '#{@login_user}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
end | ||
|
||
it "Test Case C89119: create login with optional 'check_policy'" do | ||
#This test also cover test case C89123: create login with optional 'instance' | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::login{'#{@login_user}': | ||
instance => 'MSSQLSERVER', | ||
login_type => 'SQL_LOGIN', | ||
password => '#{@login_passwd}', | ||
svrroles => {'sysadmin' => 1}, | ||
check_policy => true, | ||
} | ||
|
||
MANIFEST | ||
ensure_manifest_apply(host, pp) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and able to access database '#{db_name}':" | ||
query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{table_name}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and has correct is_expiration_checked:" | ||
query = "SELECT name as LOGIN_NAME, is_policy_checked | ||
FROM SYS.SQL_LOGINS | ||
WHERE is_policy_checked = '1' | ||
AND name = '#{@login_user}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
end | ||
|
||
it "Test Case C89120: create login with optional 'default_database'" do | ||
#This test also cover test case C89124: create login with optional 'login_type' | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::login{'#{@login_user}': | ||
instance => 'MSSQLSERVER', | ||
login_type => 'SQL_LOGIN', | ||
password => '#{@login_passwd}', | ||
svrroles => {'sysadmin' => 1}, | ||
default_database => '#{db_name}', | ||
} | ||
|
||
MANIFEST | ||
ensure_manifest_apply(host, pp) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and able to access database '#{db_name}':" | ||
query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{table_name}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and has correct default_database:" | ||
query = "SELECT name as LOGIN_NAME, default_database_name | ||
FROM SYS.SQL_LOGINS | ||
WHERE default_database_name = '#{db_name}' | ||
AND name = '#{@login_user}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
end | ||
|
||
it "Test Case C89121: create login with optional 'default_language'" do | ||
#This test also cover test case C89125: create login with optional 'svrroles' | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::login{'#{@login_user}': | ||
instance => 'MSSQLSERVER', | ||
login_type => 'SQL_LOGIN', | ||
password => '#{@login_passwd}', | ||
svrroles => {'sysadmin' => 1}, | ||
default_language => 'Spanish', | ||
} | ||
MANIFEST | ||
ensure_manifest_apply(host, pp) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and able to access database '#{db_name}':" | ||
query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{table_name}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and has correct default_language_name:" | ||
query = "SELECT name as LOGIN_NAME, default_language_name | ||
FROM SYS.SQL_LOGINS | ||
WHERE default_language_name = 'Spanish' | ||
AND name = '#{@login_user}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
end | ||
|
||
#Temporarily skip this test because of ticket MODULES-2305 | ||
xit "Test Case C89122: create login with optional 'disabled'" do | ||
pp = <<-MANIFEST | ||
sqlserver::config{'MSSQLSERVER': | ||
admin_user => 'sa', | ||
admin_pass => 'Pupp3t1@', | ||
} | ||
sqlserver::login{'#{@login_user}': | ||
instance => 'MSSQLSERVER', | ||
login_type => 'SQL_LOGIN', | ||
password => '#{@login_passwd}', | ||
svrroles => {'sysadmin' => 1}, | ||
disabled => true, | ||
} | ||
MANIFEST | ||
ensure_manifest_apply(host, pp) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and able to access database '#{db_name}':" | ||
query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{table_name}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and has correct is_disabled:" | ||
query = "SELECT name as LOGIN_NAME, is_policy_checked | ||
FROM SYS.SQL_LOGINS | ||
WHERE is_disabled = '1' | ||
AND name = '#{@login_user}';" | ||
run_sql_query(host, run_sql_query_opts(@login_user, @login_passwd, query, expected_row_count = 1)) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you not use the Beaker built-in method "expect_failure" from Beaker-RSpec?