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

Refactor E2E test suite + add RSA tests #60

Merged
merged 7 commits into from
Sep 20, 2024

Conversation

puffitos
Copy link
Collaborator

Please merge before #59, as this is part of testing the feature introduced in the PR to solve #57. Once it's merged we can also merge 59 into main and do a release.

Motivation

  • The new RSA feature had to be thoroughly tested
  • The tests had to be extended without greatly replicating the code

Changes done

The E2E test cases were refactored to allow passing a signing function and the framework itself, to avoid having to create the framework in each test. Since the tests cases now don't just accept testing.T as an argument, they were refactored to return a function, so each case can still be run by calling t.Run(testCase).

The next logical step seemed to be to wrap the testing.T type in our own Framework, as this is the role it principally plays: the testing framework for the E2E test cases. We let the Framework centrally take care of handling errors & checking whether a test passed or failed and skip micromanaging in each function of the Framework (each function did its own cleanup and called t.Fatal each time). We simplify the Framework by introducing graceful error handling (let everything fail and show first error) and letting each test case follow the same pattern:

  • Prepare resources for test
  • Sign images
  • Do deployments & create any needed resources
  • Do assertions
  • Do cleanup

The Framework will do the rest. New tests just need to adhere to this pattern.

Tests done

  • New E2E tests pass

The tests have been refactored to use a dedicated struct for the private
and public keys, which contains the key itself and the path to it.

This will allow a bigger refactoring of the E2E tests, so that each test case can
be run independently of what type of key is used for signing & validation

Signed-off-by: Bruno Bressi <[email protected]>
Instead of hardcoding the path in all tests, the value is derived from the previously
unused private key variable returned. This way, the tests can now be refactored to run
by only passing the key creation function

Signed-off-by: Bruno Bressi <[email protected]>
The framework struct has been refactored to abstract the golang testing framework.
This allows the E2E test cases to be written without having to create a new framework for each test.
The framework functions now do not have to do a lot of micromanagement and cleanup; they just check
whether an error has happened and they return. This allows for new functions to be written without having
to think about whether to fail the test or not.

The cleanup function takes care of the final step; cleaning up everything and then deciding whether the test
failed or passed.

Additionally, a new type is introduced, which will be used to wrap the tests cases, so they can be
run used t.Run.
The test cases are now refactored to accept a signing function, so that
the same test can be run regardless of RSA/ECDSA key without having to
write too much duplicate code.

The new fuction type is used for the signing function and each test case
must now return the set of actions required for the use case to be
tested, wrapped in a func which returns testing.T, so it may be run by
the t.Run method.
Added variable so that the additional E2E test is also executed. This
test must be refactored in a future commit/ removed, as it depends on an
image already being present on the machine running the test.
Each case tests for ECDSA keys is now also tested for RSA keys.

The tests were also accelerated by reducing the delay between checks
from 5s to 500m

Signed-off-by: Bruno Bressi <[email protected]>
@puffitos puffitos added the enhancement New feature or request label Sep 19, 2024
@puffitos puffitos requested a review from eumel8 September 19, 2024 20:58
@puffitos puffitos self-assigned this Sep 19, 2024
Copy link
Owner

@eumel8 eumel8 left a comment

Choose a reason for hiding this comment

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

LGTM

@eumel8 eumel8 merged commit 6b3f0ca into feat/rsa-keys Sep 20, 2024
12 checks passed
@eumel8 eumel8 deleted the refactor/e2e-key-suites branch September 20, 2024 08:31
eumel8 pushed a commit that referenced this pull request Sep 20, 2024
* test: added rsa generation

This allows the test framework to generate RSA keys

Signed-off-by: Bruno Bressi <[email protected]>

* chore: use another port for k3d registry

The port 5000 is used in mac for some other server.

* feat: new rsa E2E test

Additionally bumped dependencies & code to go 1.23

* feat: added RSA key support in verification process

Signed-off-by: Bruno Bressi <[email protected]>

* chore: formatting

Signed-off-by: Bruno Bressi <[email protected]>

* feat: new test case for RSA

Also moved port back to 5000

Signed-off-by: Bruno Bressi <[email protected]>

* refactor: use port variable

To make the tests easier to maintain, a variable was introduced for the port used in the ephemeral private registry used.

* refactor: use constants for images

This makes the tests somewhat easier to maintain and read.

* chore: more resilient cleanup

The cleanup method can now be called always when a test is run using the framework, as it cleans up whatever is there and ignores the rest.

* fix: rsa keys now properly generated

The keys had to be also imported to the cosign format to be usable for signing containers. Additionally, this commit refactors the signing method to use the CLI directly and not the cobra command, which was kind of unintuitive.

An additional test, which doesn't run per default was added to test whether the sign method really works.

* chore: formatting

Signed-off-by: Bruno Bressi <[email protected]>

* fix: signing and RSA public key fixes

Since the switch to the `sign` module, the signatures of the ephemeral images being used in tests were not uploaded to the repository.
This resulted in test failure, as the public key had no signature to verify.

Additionally, the errors with the RSA private key not being suited for image signing and verification are also solved in this commit.
The proper encoding algorithms are now used and the the correct values are returned. The imported public key and the generated one are now the same,
and the signing private key has the correct header now.

WIP.

* test: added signImage test for RSA

A simple test locke behind an env variable to test whether an RSA key can be
used to sign a container image. In the future, this test should be an autonomous integration test
and not be connected to the busybox image created during the E2E preparation

* chore: fixed E2E test

Housekeeping commit to refactor the tests so they use the new keypath
argument, which allows them more flexibility and opens up for a future
refactoring to simplify the test suite and allow to run the same test
suite for multiple input keys (ECDSA, RSA).

* chore: removed double @@

This was a typo

Signed-off-by: Bruno Bressi <[email protected]>

* docs: explanation of dns flag in e2e tests [skip ci]

Signed-off-by: Bruno Bressi <[email protected]>

* Refactor E2E test suite + add RSA tests (#60)

* refactor: own struct for keys

The tests have been refactored to use a dedicated struct for the private
and public keys, which contains the key itself and the path to it.

This will allow a bigger refactoring of the E2E tests, so that each test case can
be run independently of what type of key is used for signing & validation

Signed-off-by: Bruno Bressi <[email protected]>

* refactor: use private key variable

Instead of hardcoding the path in all tests, the value is derived from the previously
unused private key variable returned. This way, the tests can now be refactored to run
by only passing the key creation function

Signed-off-by: Bruno Bressi <[email protected]>

* refactor: [WIP] framework wraps testing.T

The framework struct has been refactored to abstract the golang testing framework.
This allows the E2E test cases to be written without having to create a new framework for each test.
The framework functions now do not have to do a lot of micromanagement and cleanup; they just check
whether an error has happened and they return. This allows for new functions to be written without having
to think about whether to fail the test or not.

The cleanup function takes care of the final step; cleaning up everything and then deciding whether the test
failed or passed.

Additionally, a new type is introduced, which will be used to wrap the tests cases, so they can be
run used t.Run.

* refactor: use new testing schema

The test cases are now refactored to accept a signing function, so that
the same test can be run regardless of RSA/ECDSA key without having to
write too much duplicate code.

The new fuction type is used for the signing function and each test case
must now return the set of actions required for the use case to be
tested, wrapped in a func which returns testing.T, so it may be run by
the t.Run method.

* chore: added E2E variable

Added variable so that the additional E2E test is also executed. This
test must be refactored in a future commit/ removed, as it depends on an
image already being present on the machine running the test.

* test: added rsa tests cases

Each case tests for ECDSA keys is now also tested for RSA keys.

The tests were also accelerated by reducing the delay between checks
from 5s to 500m

Signed-off-by: Bruno Bressi <[email protected]>

---------

Signed-off-by: Bruno Bressi <[email protected]>

---------

Signed-off-by: Bruno Bressi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants