From 00f1a920760e64dda637e2b5266a5f59a2b7f826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Nov 2024 19:40:24 +0100 Subject: [PATCH] pam/integration-tests/ssh: Ignore SSH tests when running on unsupported OS SSH output changes from old jammy (where CI is) to noble and greater versions (as per the OpenSSH server changes we carry on), so to be able to run the tests in a reliable way we need to be on such context. While we target noble, we didn't force our CI to be updated, so for now let's just enable the tests in older ubuntu versions where CI resides skipping it otherwise. Added also a further check so that when CI changes we get an error about --- go.mod | 1 + go.sum | 2 ++ pam/integration-tests/helpers_test.go | 24 ++++++++++++++++++++++++ pam/integration-tests/ssh_test.go | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/go.mod b/go.mod index e5663c7d0..b85525c2c 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,7 @@ require ( google.golang.org/protobuf v1.34.2 gopkg.in/ini.v1 v1.67.0 gopkg.in/yaml.v3 v3.0.1 + gorbe.io/go/osrelease v0.3.0 ) require ( diff --git a/go.sum b/go.sum index 86615e341..dfe260706 100644 --- a/go.sum +++ b/go.sum @@ -144,3 +144,5 @@ gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorbe.io/go/osrelease v0.3.0 h1:RqVqqfYMbe8AkTrCovTzE+FXYNolUFrhP/ne44za/xA= +gorbe.io/go/osrelease v0.3.0/go.mod h1:kuAQu3QnfzxWIa2eppGpV3ZWAwa/7DP/m465/1I48oU= diff --git a/pam/integration-tests/helpers_test.go b/pam/integration-tests/helpers_test.go index 7062ce14c..7f4a69edf 100644 --- a/pam/integration-tests/helpers_test.go +++ b/pam/integration-tests/helpers_test.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "sync" "testing" @@ -22,6 +23,7 @@ import ( "github.com/ubuntu/authd/pam/internal/pam_test" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + "gorbe.io/go/osrelease" ) var ( @@ -242,3 +244,25 @@ func prepareGPasswdFiles(t *testing.T) (string, string) { return gpasswdOutput, groupsFile } + +func getUbuntuVersion(t *testing.T) int { + t.Helper() + + err := osrelease.Parse() + require.NoError(t, err, "Can't parse os-release file %q: %v", osrelease.Path, err) + + var versionID string + switch osrelease.Release.ID { + case "ubuntu": + versionID = strings.ReplaceAll(osrelease.Release.VersionID, ".", "") + case "ubuntu-core": + versionID = osrelease.Release.VersionID + "04" + default: + t.Logf("Not an ubuntu version: %q", osrelease.Release.ID) + return 0 + } + + v, err := strconv.Atoi(versionID) + require.NoError(t, err, "Can't parse version ID: %q", osrelease.Release.ID) + return v +} diff --git a/pam/integration-tests/ssh_test.go b/pam/integration-tests/ssh_test.go index 38a6334d0..522b10aca 100644 --- a/pam/integration-tests/ssh_test.go +++ b/pam/integration-tests/ssh_test.go @@ -48,6 +48,12 @@ func testSSHAuthenticate(t *testing.T, sharedSSHd bool) { t.Skip("Skipping tests with external dependencies as requested") } + if uv := getUbuntuVersion(t); uv == 0 || uv >= 2404 { + require.Empty(t, os.Getenv("GITHUB_REPOSITORY"), + "Golden files needs to be updated to ensure CI runs on Ubuntu %v") + t.Skipf("Skipping SSH tests since they require new golden files for Ubuntu %v", uv) + } + currentDir, err := os.Getwd() require.NoError(t, err, "Setup: Could not get current directory for the tests")