Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ platform_exceptions: {
set_native_user: true
}
}
platform_exceptions: {
platform: {
vendor: ARISTA
}
deviations: {
set_native_user: true
}
}
platform_exceptions: {
platform: {
vendor: JUNIPER
}
deviations: {
set_native_user: true
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package tls_authentication_over_grpc_test
import (
"context"
"encoding/json"
"fmt"
"testing"
"time"

Expand All @@ -37,6 +38,11 @@ func TestMain(m *testing.M) {
fptest.RunTests(m)
}

var (
password = credz.GeneratePassword()
passwordVersion = credz.GenerateVersion()
)

// helper function for native model;
// Configure a new user by passing a username and password and assign that user to a role
// ensure role has write access
Expand Down Expand Up @@ -131,13 +137,46 @@ func createNativeUser(t testing.TB, dut *ondatra.DUTDevice, user string, pass st
if _, err := gnmiClient.Set(context.Background(), SetRequest); err != nil {
t.Fatalf("Unexpected error configuring User: %v", err)
}
case ondatra.JUNIPER:
t.Logf("Rotating user password on DUT for user, pass: %s, %s", user, pass)
credz.SetupUser(t.(*testing.T), dut, user)
t.Logf("Rotating user password on DUT")
credz.RotateUserPassword(t.(*testing.T), dut, user, pass, passwordVersion, uint64(time.Now().Unix()))
case ondatra.ARISTA:
cliConfig := fmt.Sprintf("username %s privilege 15 role network-admin secret %s", user, pass)
helpers.GnmiCLIConfig(t, dut, cliConfig)
time.Sleep(5 * time.Second)
default:
t.Fatalf("Unsupported vendor %s for deviation 'deviation_native_users'", dut.Vendor())
}
}

func TestAuthentication(t *testing.T) {
dut := ondatra.DUT(t, "dut")
// Save the original hostname to restore it at the end of the test.
hostnamePath := gnmi.OC().System().Hostname().Config()
if origHostname, present := gnmi.Lookup(t, dut, hostnamePath).Val(); present {
defer func() {
var dev gnmi.DeviceOrOpts = dut
if dut.Vendor() == ondatra.CISCO {
dev = dut.GNMIOpts().WithMetadata(metadata.Pairs("username", "alice", "password", password))
}
fptest.NonFatal(t, func(t testing.TB) {
gnmi.Replace(t, dev, hostnamePath, origHostname)
})
}()
} else {
defer func() {
var dev gnmi.DeviceOrOpts = dut
if dut.Vendor() == ondatra.CISCO {
dev = dut.GNMIOpts().WithMetadata(metadata.Pairs("username", "alice", "password", password))
}
fptest.NonFatal(t, func(t testing.TB) {
gnmi.Delete(t, dev, hostnamePath)
})
}()
}

switch dut.Vendor() {
case ondatra.ARISTA:
t.Logf("Arista vendor, performing SSH cleanup")
Expand All @@ -157,7 +196,8 @@ func TestAuthentication(t *testing.T) {
helpers.GnmiCLIConfig(t, dut, cliConfig)

case ondatra.JUNIPER:
t.Logf("Juniper vendor, performing SSH configuration")
t.Logf("Juniper SSH configuration ")

cliConfig := `
system {
services {
Expand All @@ -168,18 +208,17 @@ func TestAuthentication(t *testing.T) {
authentication-order password;
}
`
helpers.GnmiCLIConfig(t, dut, cliConfig)

dut.Config().New().WithJuniperText(cliConfig).Append(t)
default:
t.Logf("No CLI config required for vendor %s", dut.Vendor())
}
if deviations.SetNativeUser(dut) {
createNativeUser(t, dut, "alice", "password", "admin")
createNativeUser(t, dut, "alice", password, "admin")
} else {
gnmi.Replace(t, dut, gnmi.OC().System().Aaa().Authentication().
User("alice").Config(), &oc.System_Aaa_Authentication_User{
Username: ygot.String("alice"),
Password: ygot.String("password"),
Password: ygot.String(password),
Role: oc.AaaTypes_SYSTEM_DEFINED_ROLES_SYSTEM_ROLE_ADMIN,
})
}
Expand All @@ -191,7 +230,7 @@ func TestAuthentication(t *testing.T) {
}{{
desc: "good username and password",
user: "alice",
pass: "password",
pass: password,
}, {
desc: "good username bad password",
user: "alice",
Expand All @@ -203,10 +242,11 @@ func TestAuthentication(t *testing.T) {
pass: "password",
wantErr: true,
}}

for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
t.Log("Trying SSH credentials")
ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 90*time.Second)
defer cancel()
var (
client any
Expand Down
Loading