-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
962f684
commit 57bd92a
Showing
2 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package emailpassword | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/supertokens/supertokens-golang/supertokens" | ||
"github.com/supertokens/supertokens-golang/test/unittesting" | ||
) | ||
|
||
var isNetworkIntercepted = false | ||
|
||
func TestNetworkInterceptorDuringSignIn(t *testing.T) { | ||
configValue := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request { | ||
isNetworkIntercepted = true | ||
return request | ||
}, | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "SuperTokens", | ||
APIDomain: "api.supertokens.io", | ||
WebsiteDomain: "supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
Init(nil), | ||
}, | ||
} | ||
BeforeEach() | ||
|
||
unittesting.StartUpST("localhost", "8080") | ||
|
||
defer AfterEach() | ||
|
||
err := supertokens.Init(configValue) | ||
|
||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
mux := http.NewServeMux() | ||
testServer := httptest.NewServer(supertokens.Middleware(mux)) | ||
defer testServer.Close() | ||
|
||
res, err := unittesting.SignInRequest("[email protected]", "validpass123", testServer.URL) | ||
|
||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
assert.Equal(t, 200, res.StatusCode) | ||
assert.Equal(t, true, isNetworkIntercepted) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters