Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

- Fixes `Invalid API key` issue on hello API

## [6.0.0] - 2023-06-02

### Adds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public String getPath() {
return "/";
}

@Override
protected boolean checkAPIKey(HttpServletRequest req) {
return false;
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
handleRequest(req, resp);
Expand Down
176 changes: 174 additions & 2 deletions src/test/java/io/supertokens/test/HelloAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import io.supertokens.pluginInterface.multitenancy.*;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.test.httpRequest.HttpRequestForTesting;
import io.supertokens.test.httpRequest.HttpResponseException;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;

public class HelloAPITest {
@Rule
Expand Down Expand Up @@ -165,4 +165,176 @@ public void testHelloAPIWithBasePath3() throws Exception {
process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

@Test
public void testWithBasePathThatHelloAPIDoesNotRequireAPIKeys() throws Exception {
String[] args = {"../"};

TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false);
FeatureFlagTestContent.getInstance(process.getProcess())
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY});
Utils.setValueInConfig("api_keys", "asdfasdfasdf123412341234");
Utils.setValueInConfig("base_path", "/hello");

process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier(null, "hello", null),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new PasswordlessConfig(true),
new JsonObject()
), false);

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier(null, "hello", "hello"),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new PasswordlessConfig(true),
new JsonObject()
), false);

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier(null, null, "hello"),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new PasswordlessConfig(true),
new JsonObject()
), false);

String res;

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/hello/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/hello/hello/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/hello/appid-hello/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/hello/appid-hello/hello/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

// Not found
try {
res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/abcd", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
fail();
} catch (HttpResponseException e) {
assertEquals(404, e.statusCode);
}

try {
res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
fail();
} catch (HttpResponseException e) {
assertEquals(404, e.statusCode);
}

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

@Test
public void testThatHelloAPIDoesNotRequireAPIKeys() throws Exception {
String[] args = {"../"};

TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false);
FeatureFlagTestContent.getInstance(process.getProcess())
.setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY});
Utils.setValueInConfig("api_keys", "asdfasdfasdf123412341234");

process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier(null, "hello", null),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new PasswordlessConfig(true),
new JsonObject()
), false);

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier(null, "hello", "hello"),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new PasswordlessConfig(true),
new JsonObject()
), false);

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier(null, null, "hello"),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new PasswordlessConfig(true),
new JsonObject()
), false);

String res;

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/hello/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/appid-hello/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

res = HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/appid-hello/hello/hello", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
assertEquals("Hello", res);

// Not found
try {
HttpRequestForTesting.sendGETRequest(process.getProcess(), "",
"http://localhost:3567/abcd", null, 1000, 1000,
null, Utils.getCdiVersionStringLatestForTests(), "");
fail();
} catch (HttpResponseException e) {
assertEquals(404, e.statusCode);
}

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}
}