Skip to content

Commit

Permalink
fixes bug related to pointer being used in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed May 13, 2024
1 parent 39c39eb commit 4180c5c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
82 changes: 82 additions & 0 deletions recipe/thirdparty/authorisationUrlFeature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,88 @@ func TestReqWithThirdPartyEmailPasswordRecipe(t *testing.T) {
assert.Equal(t, "/dev/oauth/redirect-to-provider", fetchedUrl.Path)
}

func TestReqWithThirdPartyEmailPasswordRecipe2(t *testing.T) {
configValue := supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "http://localhost:8080",
},
AppInfo: supertokens.AppInfo{
APIDomain: "api.supertokens.io",
AppName: "SuperTokens",
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
Init(
&tpmodels.TypeInput{
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
Providers: []tpmodels.ProviderInput{
{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "google",
Clients: []tpmodels.ProviderClientConfig{
{
ClientID: "4398792-test-id",
ClientSecret: "test-secret",
},
},
},
},
},
},
},
),
emailpassword.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()

client := &http.Client{}
req, _ := http.NewRequest("GET", testServer.URL+"/auth/authorisationurl?thirdPartyId=google", nil)

req.Header.Add("Content-Type", "application/json")
req.Header.Add("rid", "thirdpartyemailpassword")

resp, err := client.Do(req)

if err != nil {
t.Error(err.Error())
}

dataInBytes, err := io.ReadAll(resp.Body)
if err != nil {
t.Error(err.Error())
}
resp.Body.Close()

var data map[string]interface{}
err = json.Unmarshal(dataInBytes, &data)
if err != nil {
t.Error(err.Error())
}

assert.Equal(t, "OK", data["status"])

fetchedUrl, err := url.Parse(data["urlWithQueryParams"].(string))
if err != nil {
t.Error(err.Error())
}

assert.Equal(t, "supertokens.io", fetchedUrl.Host)
assert.Equal(t, "/dev/oauth/redirect-to-provider", fetchedUrl.Path)
}

func TestUsingDevOAuthKeysWillUseDevAuthUrl(t *testing.T) {
configValue := supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
Expand Down
6 changes: 3 additions & 3 deletions supertokens/supertokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (s *superTokens) middleware(theirHandler http.Handler) http.Handler {

var id *string = nil
var finalTenantId *string = nil
var finalMatchedRecipe *RecipeModule = nil
var finalMatchedRecipe RecipeModule = RecipeModule{}

for _, matchedRecipe := range matchedRecipes {
currId, currTenantId, err := matchedRecipe.ReturnAPIIdIfCanHandleRequest(path, method, userContext)
Expand All @@ -231,12 +231,12 @@ func (s *superTokens) middleware(theirHandler http.Handler) http.Handler {
} else {
id = currId
finalTenantId = &currTenantId
finalMatchedRecipe = &matchedRecipe
finalMatchedRecipe = matchedRecipe
}
}
}

if id == nil || finalTenantId == nil || finalMatchedRecipe == nil {
if id == nil || finalTenantId == nil {
s.middlewareHelperHandleWithoutRid(path, method, userContext, theirHandler, dw, r)
return
}
Expand Down

0 comments on commit 4180c5c

Please sign in to comment.