-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
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', '891540']} 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}'], | ||
} | ||
-> | ||
sqlserver_features{ 'features_forUI': | ||
source => 'H:', | ||
features => ['Tools', 'IS', 'MDS'], | ||
} | ||
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) | ||
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. Can you not use the Beaker built-in method "expect_failure" from Beaker-RSpec? |
||
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: | ||
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, 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, 1)) | ||
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. This is a slightly different pattern than what I saw in previous test suites. Can you explain this to me in more detail? (We can do it just face-to-face.) 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. Use the "expected_row_count" keyword for the last argument in the function call to make it clear. 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. There are two things different from previous tests in the test suites:
|
||
end | ||
|
||
it "Test Case C89119: create login with optional 'check_policy'" 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_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, 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, 1)) | ||
end | ||
|
||
it "Test Case C89120: create login with optional 'default_database'" 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}, | ||
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, 1)) | ||
|
||
puts "Validate the login '#{@login_user}' is successfully created and has correct is_expiration_checked:" | ||
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. Message text is incorrect. 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. Fixed in the next push |
||
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, 1)) | ||
end | ||
|
||
it "Test Case C89121: create login with optional 'default_language'" 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}, | ||
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, 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, 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, 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, 1)) | ||
end | ||
end | ||
end |
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.
Test case ID
891540
should be89540
.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.
fixed in the next push