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

fix(windows-agent): Generate test certificates dynamically #398

Merged
merged 4 commits into from
Nov 14, 2023

Conversation

EduardGomezEscandell
Copy link
Contributor

The certificates used in Landscape tests had an expiration date, which I did not notice. This expiration date has arrived and the tests are now failing.

This PR fixes this by generating the certificate dynamically in every test run.


UDENG-1719

@EduardGomezEscandell EduardGomezEscandell self-assigned this Nov 14, 2023
This certificate has an expiry date, which is not very convenient for
tests.
This way we prevent test coupling.
@EduardGomezEscandell EduardGomezEscandell marked this pull request as ready for review November 14, 2023 09:33
Copy link
Collaborator

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

One minor nitpick IMHO that worths debating, but this is exactly what we needed for the tests. Thanks for looking at it!

@@ -108,18 +134,15 @@ func TestConnect(t *testing.T) {
landscapeAgentUID: tc.uid,
}

out, err := os.ReadFile(filepath.Join(golden.TestFixturePath(t), "landscape.conf"))
in, err := os.ReadFile(filepath.Join(golden.TestFixturePath(t), "landscape.conf"))
if errors.Is(err, os.ErrNotExist) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we reverse the logic? Like:

  • set default
  • load override if exists (so changing to err == nil). I agree that we then silence require.NoError for any other kinds of error and fallback to default config. I’m happy to have counter-arguments, but I still find loading default and then overriding being way more logical (I had to reread twice) :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, default then override is the Go way :)

SerialNumber: big.NewInt(1),
Subject: pkix.Name{
CommonName: "CanonicalGroupLimited",
Country: []string{"US"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

UK? :p

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 actually based it on what we use in the app manifest 😅:

https://github.com/canonical/ubuntu-pro-for-windows/blob/b2050bbb38834580ac37699e7a679e172286f389/msix/UbuntuProForWindows/Package.appxmanifest#L16

Although I think we could set it to Narnia and it'd still work 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

Narnia

Thanks for letting me once again feel old :p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's from the 1950's, you're not that old!

didrocks
didrocks previously approved these changes Nov 14, 2023
Copy link
Collaborator

@didrocks didrocks left a comment

Choose a reason for hiding this comment

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

One last typo to fix and you can rebase/merge!

We were modifying the fixtures too much:
- find and replace for certificate
- appending the hostagent URL section

This meant that the config in the fixture bore little similarity to
the one being used in the end. I switched to templates for the sake of
clarity. Now the fixtures look much more like the final config.
@EduardGomezEscandell
Copy link
Contributor Author

Applied suggestion and did some squashing.

@EduardGomezEscandell EduardGomezEscandell merged commit bf1f191 into main Nov 14, 2023
33 of 34 checks passed
@EduardGomezEscandell EduardGomezEscandell deleted the fix-expired-certificates branch November 14, 2023 13:45
EduardGomezEscandell added a commit that referenced this pull request Dec 12, 2023
This pull request sets up the Landscape mock server in both registry and
manually provided token tests.


This PR depends on #377 for Landscape mock service fixes and #398 for
dynamic certificate generation.

---
UDENG-1549
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.

2 participants