test(e2e): Add tests for bytes_up/bytes_down (#2740)
* refact(e2e): Create env files for consistency * refact(e2e): Addmethod for waiting for session * test(e2e): Add bytes up/down test * fix(e2e): Fix require.Equal statements to have the correct order * fix(e2e): Fix loop variable
This commit is contained in:
1 parent
895aecb58c
commit
fdf3318f72
17 files changed
+384
-178
No files matched your search
@@ -0,0 +1,92 @@
|
||||
package static_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/api/sessions"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestCliBytesUpDownEmpty uses the cli to verify that the bytes_up/bytes_down fields of a
|
||||
// session correctly increase when data is transmitting during a session.
|
||||
func TestCliBytesUpDownEmpty(t *testing.T) {
|
||||
e2e.MaybeSkipTest(t)
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
newOrgId := boundary.CreateNewOrgCli(t, ctx)
|
||||
t.Cleanup(func() {
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
|
||||
|
||||
// Create a session where no additional commands are run
|
||||
ctxCancel, cancel := context.WithCancel(context.Background())
|
||||
errChan := make(chan *e2e.CommandResult)
|
||||
go func() {
|
||||
t.Log("Starting session...")
|
||||
errChan <- e2e.RunCommand(ctxCancel, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", c.TargetSshUser,
|
||||
"-i", c.TargetSshKeyPath,
|
||||
"-o", "UserKnownHostsFile=/dev/null",
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
|
||||
"-p", "{{boundary.port}}", // this is provided by boundary
|
||||
"{{boundary.ip}}",
|
||||
),
|
||||
)
|
||||
}()
|
||||
t.Cleanup(cancel)
|
||||
|
||||
session := boundary.WaitForSessionCli(t, ctx, newProjectId)
|
||||
assert.Equal(t, newTargetId, session.TargetId)
|
||||
assert.Equal(t, newHostId, session.HostId)
|
||||
|
||||
// Confirm that bytesUp and bytesDown do not change
|
||||
bytesUp := 0
|
||||
bytesDown := 0
|
||||
t.Log("Reading bytes_up/bytes_down values...")
|
||||
for i := 0; i < 3; i++ {
|
||||
if i != 0 {
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newSessionReadResult sessions.SessionReadResult
|
||||
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
|
||||
require.NoError(t, err)
|
||||
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
|
||||
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
|
||||
|
||||
if i != 1 {
|
||||
require.Equal(t, bytesUp, int(newSessionReadResult.Item.Connections[0].BytesUp))
|
||||
require.Equal(t, bytesDown, int(newSessionReadResult.Item.Connections[0].BytesDown))
|
||||
}
|
||||
|
||||
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package static_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/api/sessions"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestCliBytesUpDownTransferData uses the cli to verify that the bytes_up/bytes_down fields of a
|
||||
// session correctly increase when data is transmitting during a session.
|
||||
func TestCliBytesUpDownTransferData(t *testing.T) {
|
||||
e2e.MaybeSkipTest(t)
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
newOrgId := boundary.CreateNewOrgCli(t, ctx)
|
||||
t.Cleanup(func() {
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateAdminCli(t, ctx)
|
||||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
|
||||
|
||||
// Create a session where no additional commands are run
|
||||
ctxCancel, cancel := context.WithCancel(context.Background())
|
||||
errChan := make(chan *e2e.CommandResult)
|
||||
|
||||
// Run commands on the target to send data through connection
|
||||
go func() {
|
||||
t.Log("Starting session...")
|
||||
errChan <- e2e.RunCommand(ctxCancel, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", c.TargetSshUser,
|
||||
"-i", c.TargetSshKeyPath,
|
||||
"-o", "UserKnownHostsFile=/dev/null",
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
|
||||
"-p", "{{boundary.port}}", // this is provided by boundary
|
||||
"{{boundary.ip}}",
|
||||
"for i in {1..10}; do pwd; sleep 1s; done",
|
||||
),
|
||||
)
|
||||
}()
|
||||
t.Cleanup(cancel)
|
||||
|
||||
session := boundary.WaitForSessionToBeActiveCli(t, ctx, newProjectId)
|
||||
assert.Equal(t, newTargetId, session.TargetId)
|
||||
assert.Equal(t, newHostId, session.HostId)
|
||||
|
||||
// Confirm that bytesDown is increasing
|
||||
bytesUp := 0
|
||||
bytesDown := 0
|
||||
t.Log("Reading bytes_up/bytes_down values...")
|
||||
for i := 0; i < 3; i++ {
|
||||
if i != 0 {
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newSessionReadResult sessions.SessionReadResult
|
||||
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
|
||||
require.NoError(t, err)
|
||||
require.GreaterOrEqual(t, int(newSessionReadResult.Item.Connections[0].BytesUp), bytesUp)
|
||||
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
|
||||
require.Greater(t, int(newSessionReadResult.Item.Connections[0].BytesDown), bytesDown)
|
||||
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
|
||||
|
||||
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,11 @@ package static_test
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/hashicorp/boundary/api/sessions"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -55,41 +52,7 @@ func TestCliConnectTargetWithLocalhost(t *testing.T) {
|
||||
}()
|
||||
t.Cleanup(cancel)
|
||||
|
||||
// Wait for session to appear
|
||||
t.Log("Waiting for session to appear...")
|
||||
err = backoff.RetryNotify(
|
||||
func() error {
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "list", "-scope-id", newProjectId, "-format", "json"),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
}
|
||||
|
||||
var sessionListResult sessions.SessionListResult
|
||||
err := json.Unmarshal(output.Stdout, &sessionListResult)
|
||||
if err != nil {
|
||||
return backoff.Permanent(err)
|
||||
}
|
||||
|
||||
sessionCount := len(sessionListResult.Items)
|
||||
if sessionCount == 0 {
|
||||
return errors.New("No items are appearing in the session list")
|
||||
}
|
||||
|
||||
t.Logf("Found %d session(s)", sessionCount)
|
||||
if sessionCount != 1 {
|
||||
return backoff.Permanent(errors.New("Only one session was expected to be found"))
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
|
||||
func(err error, td time.Duration) {
|
||||
t.Logf("%s. Retrying...", err.Error())
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
boundary.WaitForSessionCli(t, ctx, newProjectId)
|
||||
|
||||
// Connect to target and print host's IP address
|
||||
output := e2e.RunCommand(ctx, "ssh",
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestCliSessionCancelAdmin(t *testing.T) {
|
||||
select {
|
||||
case output := <-errChan:
|
||||
// `boundary connect` returns a 255 when cancelled
|
||||
require.Equal(t, output.ExitCode, 255, string(output.Stdout), string(output.Stderr))
|
||||
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timed out waiting for session command to exit")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package static_test
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -83,7 +84,7 @@ func TestCliSessionCancelGroup(t *testing.T) {
|
||||
var response boundary.CliError
|
||||
err = json.Unmarshal(output.Stderr, &response)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 403, int(response.Status))
|
||||
require.Equal(t, http.StatusForbidden, int(response.Status))
|
||||
t.Log("Successfully received an error when connecting to target as a user without permissions")
|
||||
|
||||
// Create a group
|
||||
@@ -168,7 +169,7 @@ func TestCliSessionCancelGroup(t *testing.T) {
|
||||
select {
|
||||
case output := <-errChan:
|
||||
// `boundary connect` returns a 255 when cancelled
|
||||
require.Equal(t, output.ExitCode, 255, string(output.Stdout), string(output.Stderr))
|
||||
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timed out waiting for session command to exit")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package static_test
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -82,7 +83,7 @@ func TestCliSessionCancelUser(t *testing.T) {
|
||||
var response boundary.CliError
|
||||
err = json.Unmarshal(output.Stderr, &response)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 403, int(response.Status))
|
||||
require.Equal(t, http.StatusForbidden, int(response.Status))
|
||||
t.Log("Successfully received an error when connecting to target as a user without permissions")
|
||||
|
||||
// Create a role for user
|
||||
@@ -142,7 +143,7 @@ func TestCliSessionCancelUser(t *testing.T) {
|
||||
select {
|
||||
case output := <-errChan:
|
||||
// `boundary connect` returns a 255 when cancelled
|
||||
require.Equal(t, output.ExitCode, 255, string(output.Stdout), string(output.Stderr))
|
||||
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timed out waiting for session command to exit")
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
|
||||
select {
|
||||
case output := <-errChan:
|
||||
// `boundary connect` returns a 255 when cancelled
|
||||
require.Equal(t, output.ExitCode, 255, string(output.Stdout), string(output.Stderr))
|
||||
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timed out waiting for session command to exit")
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
|
||||
select {
|
||||
case output := <-errChan:
|
||||
// `boundary connect` returns a 255 when cancelled
|
||||
require.Equal(t, output.ExitCode, 255, string(output.Stdout), string(output.Stderr))
|
||||
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timed out waiting for session command to exit")
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
|
||||
select {
|
||||
case output := <-errChan:
|
||||
// `boundary connect` returns a 255 when cancelled
|
||||
require.Equal(t, output.ExitCode, 255, string(output.Stdout), string(output.Stderr))
|
||||
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timed out waiting for session command to exit")
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
|
||||
select {
|
||||
case output := <-errChan:
|
||||
// `boundary connect` returns a 255 when cancelled
|
||||
require.Equal(t, output.ExitCode, 255, string(output.Stdout), string(output.Stderr))
|
||||
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
||||
case <-time.After(time.Second * 5):
|
||||
t.Fatal("Timed out waiting for session command to exit")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user