Skip to content

Commit

Permalink
pam/integration-tests/ssh: Ignore SSH tests when running on unsupport…
Browse files Browse the repository at this point in the history
…ed 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
  • Loading branch information
3v1n0 committed Nov 13, 2024
1 parent c3c8e13 commit b89f5f5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
24 changes: 24 additions & 0 deletions pam/integration-tests/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
"testing"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions pam/integration-tests/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit b89f5f5

Please sign in to comment.