Skip to content
Draft
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
19 changes: 11 additions & 8 deletions tests/integration/authn/oauth_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
const (
oauthAuthStart = "/auth/oauth/standard/start"
oauthAuthFinish = "/auth/oauth/standard/finish"
mockOAuthPort = 8092
)

var oauthAuthTestOU = testutils.OrganizationUnit{
Expand Down Expand Up @@ -82,8 +81,16 @@ func TestOAuthAuthTestSuite(t *testing.T) {
}

func (suite *OAuthAuthTestSuite) SetupSuite() {
suite.mockOAuthServer = testutils.NewMockOAuthServer(mockOAuthPort,
// Get shared OAuth server (started once for all test suites)
var err error
suite.mockOAuthServer, err = testutils.GetSharedMockServers().GetOAuthServer(
"test-oauth-client", "test-oauth-secret")
if err != nil {
suite.T().Fatalf("Failed to get shared OAuth server: %v", err)
}

// Reset the server to clear any state from previous test suites
suite.mockOAuthServer.Reset()

suite.mockOAuthServer.AddUser(&testutils.OAuthUserInfo{
Sub: "user123",
Expand All @@ -96,9 +103,6 @@ func (suite *OAuthAuthTestSuite) SetupSuite() {
},
})

err := suite.mockOAuthServer.Start()
suite.Require().NoError(err, "Failed to start mock OAuth server")

ouID, err := testutils.CreateOrganizationUnit(oauthAuthTestOU)
suite.Require().NoError(err, "Failed to create test organization unit")
suite.ouID = ouID
Expand Down Expand Up @@ -191,9 +195,8 @@ func (suite *OAuthAuthTestSuite) TearDownSuite() {
_ = testutils.DeleteIDP(suite.idpID)
}

if suite.mockOAuthServer != nil {
_ = suite.mockOAuthServer.Stop()
}
// Note: We don't stop the mock server here because it's shared across test suites.
// The shared server will be cleaned up when the test process exits.

if suite.ouID != "" {
if err := testutils.DeleteOrganizationUnit(suite.ouID); err != nil {
Expand Down
19 changes: 10 additions & 9 deletions tests/integration/authn/oidc_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
const (
oidcAuthStart = "/auth/oauth/standard/start"
oidcAuthFinish = "/auth/oauth/standard/finish"
mockOIDCPort = 8093
)

var oidcAuthTestOU = testutils.OrganizationUnit{
Expand Down Expand Up @@ -81,10 +80,16 @@ func TestOIDCAuthTestSuite(t *testing.T) {
}

func (suite *OIDCAuthTestSuite) SetupSuite() {
// Get shared OIDC server (started once for all test suites)
var err error
suite.mockOIDCServer, err = testutils.NewMockOIDCServer(mockOIDCPort,
suite.mockOIDCServer, err = testutils.GetSharedMockServers().GetOIDCServer(
"test-oidc-client", "test-oidc-secret")
suite.Require().NoError(err, "Failed to create mock OIDC server")
if err != nil {
suite.T().Fatalf("Failed to get shared OIDC server: %v", err)
}

// Reset the server to clear any state from previous test suites
suite.mockOIDCServer.Reset()

suite.mockOIDCServer.AddUser(&testutils.OIDCUserInfo{
Sub: "user456",
Expand All @@ -100,9 +105,6 @@ func (suite *OIDCAuthTestSuite) SetupSuite() {
},
})

err = suite.mockOIDCServer.Start()
suite.Require().NoError(err, "Failed to start mock OIDC server")

ouID, err := testutils.CreateOrganizationUnit(oidcAuthTestOU)
suite.Require().NoError(err, "Failed to create test organization unit")
suite.ouID = ouID
Expand Down Expand Up @@ -200,9 +202,8 @@ func (suite *OIDCAuthTestSuite) TearDownSuite() {
_ = testutils.DeleteIDP(suite.idpID)
}

if suite.mockOIDCServer != nil {
_ = suite.mockOIDCServer.Stop()
}
// Note: We don't stop the mock server here because it's shared across test suites.
// The shared server will be cleaned up when the test process exits.

if suite.ouID != "" {
if err := testutils.DeleteOrganizationUnit(suite.ouID); err != nil {
Expand Down
25 changes: 11 additions & 14 deletions tests/integration/flowauthn/conditional_exec_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ package flowauthn
import (
"encoding/json"
"testing"
"time"

"github.com/asgardeo/thunder/tests/integration/testutils"
"github.com/stretchr/testify/suite"
)

const (
conditionalExecMockGooglePort = 8093
conditionalExecNewUserSub = "conditional-exec-new-user-sub"
conditionalExecNewUserEmail = "newuser@conditional-exec-test.com"
conditionalExecExistingUserSub = "conditional-exec-existing-user-sub"
Expand Down Expand Up @@ -91,11 +89,16 @@ func TestConditionalExecAuthFlowTestSuite(t *testing.T) {
}

func (ts *ConditionalExecAuthFlowTestSuite) SetupSuite() {
// Start mock Google server
mockGoogleServer, err := testutils.NewMockGoogleOIDCServer(conditionalExecMockGooglePort,
// Get shared Google OIDC server (started once for all test suites)
var err error
ts.mockGoogleServer, err = testutils.GetSharedMockServers().GetGoogleServer(
"test_google_client", "test_google_secret")
ts.Require().NoError(err, "Failed to create mock Google server")
ts.mockGoogleServer = mockGoogleServer
if err != nil {
ts.T().Fatalf("Failed to get shared Google server: %v", err)
}

// Reset the server to clear any state from previous test suites
ts.mockGoogleServer.Reset()

// Add test users
ts.mockGoogleServer.AddUser(&testutils.GoogleUserInfo{
Expand All @@ -119,9 +122,6 @@ func (ts *ConditionalExecAuthFlowTestSuite) SetupSuite() {
Locale: "en",
})

err = ts.mockGoogleServer.Start()
ts.Require().NoError(err, "Failed to start mock Google server")

// Create test organization unit
ouID, err := testutils.CreateOrganizationUnit(conditionalExecTestOU)
ts.Require().NoError(err, "Failed to create test organization unit")
Expand Down Expand Up @@ -186,11 +186,8 @@ func (ts *ConditionalExecAuthFlowTestSuite) TearDownSuite() {
_ = testutils.DeleteOrganizationUnit(conditionalExecPreCreatedOUID)
}

// Stop mock server
if ts.mockGoogleServer != nil {
_ = ts.mockGoogleServer.Stop()
time.Sleep(200 * time.Millisecond)
}
// Note: We don't stop the mock server here because it's shared across test suites.
// The shared server will be cleaned up when the test process exits.
}

func (ts *ConditionalExecAuthFlowTestSuite) TestSkipConditionalNodes() {
Expand Down
23 changes: 7 additions & 16 deletions tests/integration/flowauthn/decision_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import (
"github.com/stretchr/testify/suite"
)

const (
mockDecisionNotificationServerPort = 8098
)


var (
decisionTestApp = testutils.Application{
Expand Down Expand Up @@ -139,14 +137,12 @@ func (ts *DecisionAndMFAFlowTestSuite) SetupSuite() {
}
decisionUserSchemaID = schemaID

// Start mock notification server
ts.mockServer = testutils.NewMockNotificationServer(mockDecisionNotificationServerPort)
err = ts.mockServer.Start()
// Get shared notification server (started once for all test suites)
ts.mockServer, err = testutils.GetSharedMockServers().GetNotificationServer()
if err != nil {
ts.T().Fatalf("Failed to start mock notification server: %v", err)
ts.T().Fatalf("Failed to get shared notification server: %v", err)
}
time.Sleep(100 * time.Millisecond)
ts.T().Log("Mock notification server started successfully")
ts.T().Log("Using shared notification server")

// Create test users with the created OU
userWithMobile := testUserWithMobileDecision
Expand Down Expand Up @@ -180,13 +176,8 @@ func (ts *DecisionAndMFAFlowTestSuite) TearDownSuite() {
ts.T().Logf("Failed to cleanup users during teardown: %v", err)
}

// Stop mock server
if ts.mockServer != nil {
err := ts.mockServer.Stop()
if err != nil {
ts.T().Logf("Failed to stop mock notification server during teardown: %v", err)
}
}
// Note: We don't stop the mock server here because it's shared across test suites.
// The shared server will be cleaned up when the test process exits.

// Delete test application
if decisionTestAppID != "" {
Expand Down
27 changes: 12 additions & 15 deletions tests/integration/flowauthn/github_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net/url"
"strings"
"testing"
"time"

"github.com/asgardeo/thunder/tests/integration/testutils"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -51,9 +50,7 @@ var (
}
)

const (
mockGithubFlowPort = 8092
)


var githubUserSchema = testutils.UserSchema{
Name: "github_flow_user",
Expand Down Expand Up @@ -92,9 +89,16 @@ func TestGithubAuthFlowTestSuite(t *testing.T) {
}

func (ts *GithubAuthFlowTestSuite) SetupSuite() {
// Start mock GitHub server
ts.mockGithubServer = testutils.NewMockGithubOAuthServer(mockGithubFlowPort,
// Get shared GitHub OAuth server (started once for all test suites)
var err error
ts.mockGithubServer, err = testutils.GetSharedMockServers().GetGithubServer(
"test_github_client", "test_github_secret")
if err != nil {
ts.T().Fatalf("Failed to get shared GitHub server: %v", err)
}

// Reset the server to clear any state from previous test suites
ts.mockGithubServer.Reset()

email := "testuser@github.com"
ts.mockGithubServer.AddUser(&testutils.GithubUserInfo{
Expand All @@ -115,9 +119,6 @@ func (ts *GithubAuthFlowTestSuite) SetupSuite() {
},
})

err := ts.mockGithubServer.Start()
ts.Require().NoError(err, "Failed to start mock GitHub server")

// Use the IDP created by database scripts
ts.idpID = "test-github-idp-id"

Expand Down Expand Up @@ -183,12 +184,8 @@ func (ts *GithubAuthFlowTestSuite) TearDownSuite() {
_ = testutils.DeleteUserType(ts.userSchemaID)
}

// Stop mock server
if ts.mockGithubServer != nil {
_ = ts.mockGithubServer.Stop()
// Wait for port to be released
time.Sleep(200 * time.Millisecond)
}
// Note: We don't stop the mock server here because it's shared across test suites.
// The shared server will be cleaned up when the test process exits.
}

func (ts *GithubAuthFlowTestSuite) TestGithubAuthFlowInitiation() {
Expand Down
29 changes: 12 additions & 17 deletions tests/integration/flowauthn/google_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net/url"
"strings"
"testing"
"time"

"github.com/asgardeo/thunder/tests/integration/testutils"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -51,9 +50,7 @@ var (
}
)

const (
mockGoogleFlowPort = 8093
)


var googleUserSchema = testutils.UserSchema{
Name: "google_flow_user",
Expand Down Expand Up @@ -92,11 +89,16 @@ func TestGoogleAuthFlowTestSuite(t *testing.T) {
}

func (ts *GoogleAuthFlowTestSuite) SetupSuite() {
// Start mock Google server
mockServer, err := testutils.NewMockGoogleOIDCServer(mockGoogleFlowPort,
// Get shared Google OIDC server (started once for all test suites)
var err error
ts.mockGoogleServer, err = testutils.GetSharedMockServers().GetGoogleServer(
"test_google_client", "test_google_secret")
ts.Require().NoError(err, "Failed to create mock Google server")
ts.mockGoogleServer = mockServer
if err != nil {
ts.T().Fatalf("Failed to get shared Google server: %v", err)
}

// Reset the server to clear any state from previous test suites
ts.mockGoogleServer.Reset()

ts.mockGoogleServer.AddUser(&testutils.GoogleUserInfo{
Sub: "google-test-user-123",
Expand All @@ -109,9 +111,6 @@ func (ts *GoogleAuthFlowTestSuite) SetupSuite() {
Locale: "en",
})

err = ts.mockGoogleServer.Start()
ts.Require().NoError(err, "Failed to start mock Google server")

// Use the IDP created by database scripts
ts.idpID = "test-google-idp-id"

Expand Down Expand Up @@ -177,12 +176,8 @@ func (ts *GoogleAuthFlowTestSuite) TearDownSuite() {
_ = testutils.DeleteUserType(ts.userSchemaID)
}

// Stop mock server
if ts.mockGoogleServer != nil {
_ = ts.mockGoogleServer.Stop()
// Wait for port to be released
time.Sleep(200 * time.Millisecond)
}
// Note: We don't stop the mock server here because it's shared across test suites.
// The shared server will be cleaned up when the test process exits.
}

func (ts *GoogleAuthFlowTestSuite) TestGoogleAuthFlowInitiation() {
Expand Down
23 changes: 7 additions & 16 deletions tests/integration/flowauthn/http_request_executor_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import (
"github.com/stretchr/testify/suite"
)

const (
mockHTTPServerPort = 9091
)


var (
httpRequestTestApp = testutils.Application{
Expand Down Expand Up @@ -121,14 +119,12 @@ func (ts *HTTPRequestAuthFlowTestSuite) SetupSuite() {
}
httpRequestTestAppID = appID

// Start mock HTTP server
ts.mockServer = testutils.NewMockHTTPServer(mockHTTPServerPort)
err = ts.mockServer.Start()
// Get shared HTTP mock server (started once for all test suites)
ts.mockServer, err = testutils.GetSharedMockServers().GetHTTPServer()
if err != nil {
ts.T().Fatalf("Failed to start mock HTTP server: %v", err)
ts.T().Fatalf("Failed to get shared HTTP server: %v", err)
}
time.Sleep(100 * time.Millisecond)
ts.T().Log("Mock HTTP server started successfully")
ts.T().Log("Using shared HTTP mock server")

// Create test user with the created OU
testUser := httpRequestTestUser
Expand All @@ -142,13 +138,8 @@ func (ts *HTTPRequestAuthFlowTestSuite) SetupSuite() {
}

func (ts *HTTPRequestAuthFlowTestSuite) TearDownSuite() {
// Stop the mock HTTP server
if ts.mockServer != nil {
err := ts.mockServer.Stop()
if err != nil {
ts.T().Logf("Failed to stop mock HTTP server during teardown: %v", err)
}
}
// Note: We don't stop the mock server here because it's shared across test suites.
// The shared server will be cleaned up when the test process exits.

// Delete all created users
if err := testutils.CleanupUsers(ts.config.CreatedUserIDs); err != nil {
Expand Down
Loading
Loading