Skip to content
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

Implement automated tests. #21

Merged
merged 7 commits into from
Nov 5, 2019
Merged

Implement automated tests. #21

merged 7 commits into from
Nov 5, 2019

Conversation

moticless
Copy link
Contributor

The tests have a common initialization flow and set of tests that follows.

  1. Durinig intialization flow
  • the repo kubernetes-conjur-deploy is being cloned and deployed.
  • test_app namespace is being created
  • conjur master is being loaded with relevant policies
  1. Execution of set of tests is being invoked via run_tests.sh that run each test such that
  • script test_case_setup.sh run before each test
  • script test_case_teardown.sh run after each test
  • on error, execution is being terminated immediately, leaving environment untouched.

Notes:

  • Under time limitation there was some compromise on code refactoring and code convention.
  • We should consider having proper tool for manipulting yaml files.

The tests have a common initialization flow and set of tests that follows.
1. Durinig intialization flow
- the repo kubernetes-conjur-deploy is being cloned and deployed.
- test_app namespace is being created
- conjur master is being loaded with relevant policies
2. Execution of set of tests is being invoked via run_tests.sh that run each test such that
- script test_case_setup.sh run before each test
- script test_case_teardown.sh run after each test
- on each error, execution is being terminated immediately, leaving environment untouched.

Notes:
- Under time limitation there was some compromise on code refactoring and code convention.
- We should consider having proper tool for manipulting yaml files.
Copy link
Contributor

@doodlesbykumbi doodlesbykumbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments. I think the test cases could really benefit from an abstract (if it's possible). I feel like using bash is having a negative impact on readability and maintainability.

test/k8s-config/secrets-access-role.sh.yml Outdated Show resolved Hide resolved
test/k8s-config/test-env.sh.yml Outdated Show resolved Hide resolved
test/k8s-config/test-env.sh.yml Outdated Show resolved Hide resolved
test/stop Outdated Show resolved Hide resolved
Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moticless / @doodlesbykumbi Finally got some time to review this - let e know if you have any questions.

test/k8s-config/test-env.sh.yml Outdated Show resolved Hide resolved
test/test_cases/TEST_ID_1_providing_secret_successfully.sh Outdated Show resolved Hide resolved
test/test_with_summon.sh Outdated Show resolved Hide resolved
test/test_with_summon.sh Outdated Show resolved Hide resolved
test/test_with_summon.sh Show resolved Hide resolved
test/test_with_summon.sh Show resolved Hide resolved
$cli exec $(get_conjur_cli_pod_name) -- conjur variable values add $SECRET_NAME $SECRET_VALUE
set_namespace $TEST_APP_NAMESPACE_NAME
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray newline

Moti Cohen added 4 commits October 24, 2019 17:29
- Update conjur version from 5.0-stable to 5.5.0 because tests get failed on known issue : “502 Bad Gateway… nginx”
- Update conjur version from 5.0-stable to 5.5.0 because tests get failed on known issue : “502 Bad Gateway… nginx”
Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moticless Mostly non-blockers but there's a few big things that should probably addressed in this or followup PRs.

test/bootstrap.env Show resolved Hide resolved
set -euo pipefail

source $TEST_CASES_UTILS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we source a path from a variable? Should the util script(s) have a stable path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want that tests will be aware of the location of utils.sh since it is located outside of folder test_cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it. and source it only once via run_tests.sh

# related key-value from yaml file
SECRETS_DESTINATION_KEY_VALUE=${SECRETS_DESTINATION_KEY_VALUE:-"SECRETS_DESTINATION k8s_secrets"}
CONTAINER_MODE_KEY_VALUE=${CONTAINER_MODE_KEY_VALUE:-"CONTAINER_MODE init"}
K8S_SECRETS_KEY_VALUE=${K8S_SECRETS_KEY_VALUE:-"K8S_SECRETS test-k8s-secret"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a blocker for merging but this seems a bit messy of a way to specify overrides vs CLI arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an issue: Improve parameterization of test scripts

test/k8s-config/test-env.sh.yml Show resolved Hide resolved
pod_name1=$(cli_get_pods_test_env | awk '{print $1}')

echo "Verify pod $pod_name1 has environment variable 'TEST_SECRET' with value 'supersecret'"
verify_secret_value_in_pod $pod_name1 TEST_SECRET supersecret
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker either but keep in mind all of these unquoted vars are liable to injection or failure when combined with spaces or special chars


source $TEST_CASES_UTILS

# TODO: replace the following with `oc create secret`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny comment: we shouldn't use any OC-specific CLIs if we can - ideally we should be able to set everything up using vanilla kubectl for portability. oc generally doesn't provide almost any additional functionality other than for account administration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified

git clone --single-branch \
--branch $KUBERNETES_CONJUR_DEPLOY_BRANCH \
https://github.com/cyberark/kubernetes-conjur-deploy.git \
kubernetes-conjur-deploy-$UNIQUE_TEST_ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized what this code is conceptually trying to do and I missed it in my last review. Using a separate per-test branch from another repo is extremely liable to fail and would be a huge perpetual effort to maintain. I don't have much guidance on what the tests should look like but this approach should be changed asap to something sturdier (even if it means that it uses conjur-intro repo deployments).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are aware of this issue. This is what we have for now. :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a separate issue for tech debt

git clone --single-branch \
--branch $KUBERNETES_CONJUR_DEPLOY_BRANCH \
https://github.com/cyberark/kubernetes-conjur-deploy.git \
kubernetes-conjur-deploy-$UNIQUE_TEST_ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker: lots of overlap with test_in_docker.sh


exit $exit_code
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes the exit call unnecessary. If you have set -e everywhere and depend on that, that probably means that cleanup isn't properly done on failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

test/utils.sh Outdated
wait_for_it 600 "oc get dc/test-env -o jsonpath={.status.replicas} | grep '^${expected_num_replicas}$'|| oc rollout latest dc/test-env"

echo "Expecting for $expected_num_replicas deployed pods"
wait_for_it 600 "oc get pods --namespace=$TEST_APP_NAMESPACE_NAME --selector app=test-env --no-headers | wc -l | grep $expected_num_replicas"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these CLIs are hardcoded. Probably worthy to mention here that we should just use kubectl instead of oc everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified to $cli

Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moticless / @Tovli : Just 3 issues need to be opened and we ca get this approved.

# related key-value from yaml file
SECRETS_DESTINATION_KEY_VALUE=${SECRETS_DESTINATION_KEY_VALUE:-"SECRETS_DESTINATION k8s_secrets"}
CONTAINER_MODE_KEY_VALUE=${CONTAINER_MODE_KEY_VALUE:-"CONTAINER_MODE init"}
K8S_SECRETS_KEY_VALUE=${K8S_SECRETS_KEY_VALUE:-"K8S_SECRETS test-k8s-secret"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an issue: Improve parameterization of test scripts

git clone --single-branch \
--branch $KUBERNETES_CONJUR_DEPLOY_BRANCH \
https://github.com/cyberark/kubernetes-conjur-deploy.git \
kubernetes-conjur-deploy-$UNIQUE_TEST_ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a separate issue for tech debt

Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgnn7 sgnn7 merged commit fb5635f into master Nov 5, 2019
@sgnn7 sgnn7 deleted the adding_integration_tests branch November 5, 2019 15:57
conjur-jenkins pushed a commit that referenced this pull request Mar 28, 2024
…grpc

CNJR-3914: Remove vulnerable versions of grpc and go-sqlite3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants