-
Notifications
You must be signed in to change notification settings - Fork 71
An explicit test of correct and incorrect grant addition #217
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
maximmasiutin
wants to merge
1
commit into
petoju:master
from
maximmasiutin:feature/different-privileges-test
Closed
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,2 @@ | ||
| GNUmakefile text eol=lf | ||
| *.sh text eol=lf |
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
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
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
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/bin/bash | ||
| #!/usr/bin/env bash | ||
|
|
||
| touch ~/.gitcookies | ||
| chmod 0600 ~/.gitcookies | ||
|
|
||
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,15 @@ | ||
|
|
||
| set PATH=C:\cygwin64\bin;%PATH% | ||
| cd test1 | ||
| if errorlevel 1 goto exit | ||
| C:\cygwin64\bin\bash.exe ../test.sh | ||
| if errorlevel 1 goto exit | ||
| cd .. | ||
| if errorlevel 1 goto exit | ||
| cd test2 | ||
| if errorlevel 1 goto exit | ||
| C:\cygwin64\bin\bash.exe ../test.sh | ||
| :exit | ||
|
|
||
|
|
||
|
|
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,8 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| cd test1 || exit 1 | ||
| ../test.sh | ||
| cd .. || exit 1 | ||
|
|
||
| cd test2 || exit 1 | ||
| ../test.sh | ||
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,33 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| export TF_VAR_MYSQL_ROOT_USER="root" | ||
| export TF_VAR_MYSQL_ROOT_PASSWORD="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1)" | ||
| container1=$(docker run --rm --name test-mysql8.4.5-1 -e MYSQL_ROOT_PASSWORD=$TF_VAR_MYSQL_ROOT_PASSWORD -d -p 3307:3306 mysql:8.4.5 mysqld --mysql-native-password=ON) | ||
| if ! echo "$container1" | grep -Eq '^[0-9a-f]+$'; then | ||
| exit 1 | ||
| fi | ||
| container2=$(docker run --rm --name test-mysql8.4.5-2 -e MYSQL_ROOT_PASSWORD=$TF_VAR_MYSQL_ROOT_PASSWORD -d -p 3308:3306 mysql:8.4.5 mysqld --mysql-native-password=ON) | ||
| if ! echo "$container2" | grep -Eq '^[0-9a-f]+$'; then | ||
| exit 1 | ||
| fi | ||
|
|
||
|
|
||
| echo "Waiting for MySQL to become available..." | ||
| until docker exec "$container1" mysqladmin ping -h"localhost" -P3306 --silent; do | ||
| sleep 1 | ||
| done | ||
| until docker exec "$container2" mysqladmin ping -h"localhost" -P3306 --silent; do | ||
| sleep 1 | ||
| done | ||
|
|
||
|
|
||
| terraform init | ||
| terraform_code=$? | ||
| if [ $terraform_code -eq 0 ]; then | ||
| terraform apply -auto-approve | ||
| terraform_code=$? | ||
| fi | ||
|
|
||
| docker container stop $container1 | ||
| docker container stop $container2 | ||
| exit $terraform_code |
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,121 @@ | ||
| terraform { | ||
| required_providers { | ||
| mysql = { | ||
| source = "petoju/mysql" | ||
| version = ">= 3.0.37" | ||
| } | ||
| } | ||
| required_version = ">= 1.11.4" | ||
| } | ||
|
|
||
| variable "MYSQL_ROOT_USER" { | ||
| sensitive = true | ||
| type = string | ||
| } | ||
|
|
||
| variable "MYSQL_ROOT_PASSWORD" { | ||
| sensitive = true | ||
| type = string | ||
| } | ||
|
|
||
| # First provider | ||
|
|
||
| provider "mysql" { | ||
| alias = "local1" | ||
| endpoint = "localhost:3307" | ||
| username = var.MYSQL_ROOT_USER | ||
| password = var.MYSQL_ROOT_PASSWORD | ||
| } | ||
|
|
||
| resource "mysql_database" "test1" { | ||
| provider = mysql.local1 | ||
| name = "test-db" | ||
| } | ||
|
|
||
|
|
||
| resource "mysql_role" "analyst1" { | ||
| provider = mysql.local1 | ||
| name = "analyst" | ||
| } | ||
|
|
||
| resource "mysql_grant" "grant_to_role_select1" { | ||
| provider = mysql.local1 | ||
| role = mysql_role.analyst1.name | ||
| database = mysql_database.test1.name | ||
| table = "*" | ||
| privileges = ["SELECT"] | ||
| } | ||
|
|
||
| resource "mysql_grant" "grant_to_role_showroutine1" { | ||
| provider = mysql.local1 | ||
| role = mysql_role.analyst1.name | ||
| database = "*" | ||
| table = "*" | ||
| privileges = ["SHOW_ROUTINE"] | ||
| } | ||
|
|
||
| resource "mysql_grant" "grant_to_user1" { | ||
| provider = mysql.local1 | ||
| user = mysql_user.user1.user | ||
| host = "%" | ||
| database = mysql_database.test1.name | ||
| roles = [mysql_role.analyst1.name] | ||
| } | ||
|
|
||
|
|
||
| resource "mysql_user" "user1" { | ||
| provider = mysql.local1 | ||
| user = "test-user" | ||
| host = "%" | ||
| } | ||
|
|
||
| # Second provider | ||
|
|
||
| provider "mysql" { | ||
| alias = "local2" | ||
| endpoint = "localhost:3308" | ||
| username = var.MYSQL_ROOT_USER | ||
| password = var.MYSQL_ROOT_PASSWORD | ||
| } | ||
|
|
||
| resource "mysql_database" "test2" { | ||
| provider = mysql.local2 | ||
| name = "test-db" | ||
| } | ||
|
|
||
|
|
||
| resource "mysql_role" "analyst2" { | ||
| provider = mysql.local2 | ||
| name = "analyst" | ||
| } | ||
|
|
||
| resource "mysql_grant" "grant_to_role_select2" { | ||
| provider = mysql.local2 | ||
| role = mysql_role.analyst2.name | ||
| database = mysql_database.test2.name | ||
| table = "*" | ||
| privileges = ["SELECT"] | ||
| } | ||
|
|
||
| resource "mysql_grant" "grant_to_role_showroutine2" { | ||
| provider = mysql.local2 | ||
| role = mysql_role.analyst2.name | ||
| database = "*" | ||
| table = "*" | ||
| privileges = ["SHOW_ROUTINE"] | ||
| } | ||
|
|
||
| resource "mysql_grant" "grant_to_user2" { | ||
| provider = mysql.local2 | ||
| user = mysql_user.user2.user | ||
| host = "%" | ||
| database = mysql_database.test2.name | ||
| roles = [mysql_role.analyst2.name] | ||
| } | ||
|
|
||
|
|
||
| resource "mysql_user" "user2" { | ||
| provider = mysql.local2 | ||
| user = "test-user" | ||
| host = "%" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
For other changes, I understand them - but how would these scripts and directory
testhelp?Generally, tests inside
*_test.goare much better idea - terraform testing harness catches more issues than executing something manually.