test(e2e): Check that an active session ends if the user is deleted (#2588)
Adds a new test to the e2e test suite that checks that an active session ends once the user is deleted.
This commit is contained in:
1 parent
d68d57e884
commit
80cdbc305d
8 files changed
+207
-185
No files matched your search
@@ -0,0 +1,77 @@
|
||||
package boundary
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/hashicorp/boundary/api/sessions"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func WaitForSessionToBeActiveCli(t testing.TB, ctx context.Context, scopeId string) *sessions.Session {
|
||||
t.Log("Waiting for session to be active...")
|
||||
var session *sessions.Session
|
||||
err := backoff.RetryNotify(
|
||||
func() error {
|
||||
// List sessions
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "list", "-scope-id", scopeId, "-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)
|
||||
}
|
||||
|
||||
// Check if there is one session
|
||||
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"))
|
||||
}
|
||||
|
||||
// Check if session is active
|
||||
session = sessionListResult.Items[0]
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
}
|
||||
|
||||
var sessionReadResult sessions.SessionReadResult
|
||||
err = json.Unmarshal(output.Stdout, &sessionReadResult)
|
||||
if err != nil {
|
||||
return backoff.Permanent(err)
|
||||
}
|
||||
|
||||
if sessionReadResult.Item.Status != "active" {
|
||||
return errors.New(fmt.Sprintf("Waiting for session to be active... Expected: %s, Actual: %s",
|
||||
"active",
|
||||
sessionReadResult.Item.Status,
|
||||
))
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
return session
|
||||
}
|
||||
@@ -49,9 +49,17 @@ func CreateNewUserCli(t testing.TB, ctx context.Context, scopeId string) string
|
||||
t.Cleanup(func() {
|
||||
AuthenticateAdminCli(t, context.Background())
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("users", "delete", "-id", newUserId),
|
||||
e2e.WithArgs("users", "delete", "-id", newUserId, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
// Only allow an error if it's due to a Resource Not Found (404)
|
||||
// This was needed since there's a test that already deletes the user and would run into an
|
||||
// error during cleanup
|
||||
if output.Err != nil {
|
||||
var response e2e.CliError
|
||||
err := json.Unmarshal(output.Stderr, &response)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 404, int(response.Status))
|
||||
}
|
||||
})
|
||||
t.Logf("Created User: %s", newUserId)
|
||||
|
||||
|
||||
Reference in new issue
Block a user