Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 committed Jan 9, 2025
1 parent c4d77e9 commit da1288a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/api/src/api/v2/auth/saml_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"

Expand All @@ -35,6 +36,7 @@ import (
"github.com/specterops/bloodhound/src/database/types/null"
"github.com/specterops/bloodhound/src/model"
"github.com/specterops/bloodhound/src/serde"
"github.com/specterops/bloodhound/src/version"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
Expand Down Expand Up @@ -120,7 +122,10 @@ func TestAuth_CreateSSOSession(t *testing.T) {

testAuthenticator.CreateSSOSession(httpRequest, response, principalName, gothamSSO)

require.Equal(t, http.StatusForbidden, response.Code)
require.Equal(t, http.StatusFound, response.Code)
location, err := response.Result().Location()
require.Nil(t, err)
require.Equal(t, location.Query(), url.Values{"error": {"Your user is not allowed, please contact your Administrator"}})
})

t.Run("Forbidden 403 if user isn't associated with a SAML Provider", func(t *testing.T) {
Expand All @@ -142,7 +147,10 @@ func TestAuth_CreateSSOSession(t *testing.T) {

testAuthenticator.CreateSSOSession(httpRequest, response, principalName, gothamSSO)

require.Equal(t, http.StatusForbidden, response.Code)
require.Equal(t, http.StatusFound, response.Code)
location, err := response.Result().Location()
require.Nil(t, err)
require.Equal(t, location.Query(), url.Values{"error": {"Your user is not allowed, please contact your Administrator"}})
})

t.Run("Forbidden 403 if user isn't associated with specified SAML Provider", func(t *testing.T) {
Expand All @@ -166,13 +174,16 @@ func TestAuth_CreateSSOSession(t *testing.T) {
},
},
}, nil)

version.GetVersion()
principalName, err := gothamSAML.GetSAMLUserPrincipalNameFromAssertion(testAssertion)
require.Nil(t, err)

testAuthenticator.CreateSSOSession(httpRequest, response, principalName, gothamSSO)

require.Equal(t, http.StatusForbidden, response.Code)
require.Equal(t, http.StatusFound, response.Code)
location, err := response.Result().Location()
require.Nil(t, err)
require.Equal(t, location.Query(), url.Values{"error": {"Your user is not allowed, please contact your Administrator"}})
})

t.Run("Correctly fails with SAML assertion error if assertion is invalid", func(t *testing.T) {
Expand Down

0 comments on commit da1288a

Please sign in to comment.