Skip to content

Commit 09ae9f6

Browse files
ci: fixing auth-react tests (#390)
* ci: fixing install error in auth-react test * ci: update test server for auth-react tests Co-authored-by: Rishabh Poddar <[email protected]>
1 parent 106e38b commit 09ae9f6

File tree

2 files changed

+119
-35
lines changed

2 files changed

+119
-35
lines changed

.circleci/config_continue.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- checkout
3737
- run: echo "127.0.0.1 localhost.org" >> /etc/hosts
3838
- run: apt-get install lsof
39+
- run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/
3940
- run: npm i -d --force
4041
- run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2
4142
- run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2
@@ -49,6 +50,7 @@ jobs:
4950
- checkout
5051
- run: echo "127.0.0.1 localhost.org" >> /etc/hosts
5152
- run: apt-get install lsof
53+
- run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/
5254
- run: npm i -d --force
5355
- run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2
5456
- run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2

test/auth-react-server/index.js

Lines changed: 117 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ let cookieParser = require("cookie-parser");
2525
let bodyParser = require("body-parser");
2626
let http = require("http");
2727
let cors = require("cors");
28+
let EmailVerificationRaw = require("../../lib/build/recipe/emailverification/recipe").default;
29+
let EmailVerification = require("../../recipe/emailverification");
30+
let UserRolesRaw = require("../../lib/build/recipe/userroles/recipe").default;
31+
let UserRoles = require("../../recipe/userroles");
2832
let PasswordlessRaw = require("../../lib/build/recipe/passwordless/recipe").default;
2933
let Passwordless = require("../../recipe/passwordless");
3034
let ThirdPartyPasswordless = require("../../recipe/thirdpartypasswordless");
@@ -118,7 +122,7 @@ app.get("/test/getDevice", (req, res) => {
118122
});
119123

120124
app.get("/test/featureFlags", (req, res) => {
121-
const available = ["passwordless", "thirdpartypasswordless", "generalerror"];
125+
const available = ["passwordless", "thirdpartypasswordless", "generalerror", "userroles"];
122126

123127
res.send({
124128
available,
@@ -130,11 +134,18 @@ app.get("/ping", async (req, res) => {
130134
});
131135

132136
app.post("/startst", async (req, res) => {
137+
if (req.body && req.body.configUpdates) {
138+
for (const update of req.body.configUpdates) {
139+
await setKeyValueInConfig(update.key, update.value);
140+
}
141+
}
133142
let pid = await startST();
134143
res.send(pid + "");
135144
});
136145

137146
app.post("/beforeeach", async (req, res) => {
147+
deviceStore = new Map();
148+
138149
await killAllST();
139150
await setupST();
140151
res.send();
@@ -171,16 +182,74 @@ app.get("/sessioninfo", verifySession(), async (req, res) => {
171182
}
172183
});
173184

185+
app.get("/unverifyEmail", verifySession(), async (req, res) => {
186+
let session = req.session;
187+
await EmailVerification.unverifyEmail(session.getUserId());
188+
await session.fetchAndSetClaim(EmailVerification.EmailVerificationClaim);
189+
res.send({ status: "OK" });
190+
});
191+
192+
app.post("/setRole", verifySession(), async (req, res) => {
193+
let session = req.session;
194+
await UserRoles.createNewRoleOrAddPermissions(req.body.role, req.body.permissions);
195+
await UserRoles.addRoleToUser(session.getUserId(), req.body.role);
196+
await session.fetchAndSetClaim(UserRoles.UserRoleClaim);
197+
await session.fetchAndSetClaim(UserRoles.PermissionClaim);
198+
res.send({ status: "OK" });
199+
});
200+
201+
app.post(
202+
"/checkRole",
203+
verifySession({
204+
overrideGlobalClaimValidators: async (gv, _session, userContext) => {
205+
const res = [...gv];
206+
const body = await userContext._default.request.getJSONBody();
207+
if (body.role !== undefined) {
208+
const info = body.role;
209+
res.push(UserRoles.UserRoleClaim.validators[info.validator](...info.args));
210+
}
211+
212+
if (body.permission !== undefined) {
213+
const info = body.permission;
214+
res.push(UserRoles.PermissionClaim.validators[info.validator](...info.args));
215+
}
216+
return res;
217+
},
218+
}),
219+
async (req, res) => {
220+
res.send({ status: "OK" });
221+
}
222+
);
223+
174224
app.get("/token", async (_, res) => {
175225
res.send({
176226
latestURLWithToken,
177227
});
178228
});
179229

230+
app.post("/test/setFlow", (req, res) => {
231+
initST({
232+
passwordlessConfig: {
233+
contactMethod: req.body.contactMethod,
234+
flowType: req.body.flowType,
235+
createAndSendCustomTextMessage: saveCode,
236+
createAndSendCustomEmail: saveCode,
237+
},
238+
});
239+
res.sendStatus(200);
240+
});
241+
242+
app.get("/test/getDevice", (req, res) => {
243+
res.send(deviceStore.get(req.query.preAuthSessionId));
244+
});
245+
180246
app.use(errorHandler());
181247

182248
app.use(async (err, req, res, next) => {
183-
res.status(500).send(err);
249+
try {
250+
console.error(err);
251+
res.status(500).send(err);
252+
} catch (ignored) {}
184253
});
185254

186255
let server = http.createServer(app);
@@ -208,11 +277,13 @@ server.listen(process.env.NODE_PORT === undefined ? 8083 : process.env.NODE_PORT
208277
})(process.env.START === "true");
209278

210279
function initST({ passwordlessConfig } = {}) {
280+
UserRolesRaw.reset();
281+
ThirdPartyPasswordlessRaw.reset();
211282
PasswordlessRaw.reset();
283+
EmailVerificationRaw.reset();
212284
EmailPasswordRaw.reset();
213285
ThirdPartyRaw.reset();
214286
ThirdPartyEmailPasswordRaw.reset();
215-
ThirdPartyPasswordlessRaw.reset();
216287
SessionRaw.reset();
217288

218289
SuperTokensRaw.reset();
@@ -224,36 +295,44 @@ function initST({ passwordlessConfig } = {}) {
224295
createAndSendCustomEmail: saveCode,
225296
...passwordlessConfig,
226297
};
298+
227299
const recipeList = [
228-
EmailPassword.init({
300+
EmailVerification.init({
301+
mode: "OPTIONAL",
302+
createAndSendCustomEmail: (_, emailVerificationURLWithToken) => {
303+
console.log(emailVerificationURLWithToken);
304+
latestURLWithToken = emailVerificationURLWithToken;
305+
},
229306
override: {
230-
emailVerificationFeature: {
231-
apis: (oI) => {
232-
return {
233-
...oI,
234-
generateEmailVerifyTokenPOST: async function (input) {
235-
let body = await input.options.req.getJSONBody();
236-
if (body.generalError === true) {
237-
return {
238-
status: "GENERAL_ERROR",
239-
message: "general error from API email verification code",
240-
};
241-
}
242-
return oI.generateEmailVerifyTokenPOST(input);
243-
},
244-
verifyEmailPOST: async function (input) {
245-
let body = await input.options.req.getJSONBody();
246-
if (body.generalError === true) {
247-
return {
248-
status: "GENERAL_ERROR",
249-
message: "general error from API email verify",
250-
};
251-
}
252-
return oI.verifyEmailPOST(input);
253-
},
254-
};
255-
},
307+
apis: (oI) => {
308+
return {
309+
...oI,
310+
generateEmailVerifyTokenPOST: async function (input) {
311+
let body = await input.options.req.getJSONBody();
312+
if (body.generalError === true) {
313+
return {
314+
status: "GENERAL_ERROR",
315+
message: "general error from API email verification code",
316+
};
317+
}
318+
return oI.generateEmailVerifyTokenPOST(input);
319+
},
320+
verifyEmailPOST: async function (input) {
321+
let body = await input.options.req.getJSONBody();
322+
if (body.generalError === true) {
323+
return {
324+
status: "GENERAL_ERROR",
325+
message: "general error from API email verify",
326+
};
327+
}
328+
return oI.verifyEmailPOST(input);
329+
},
330+
};
256331
},
332+
},
333+
}),
334+
EmailPassword.init({
335+
override: {
257336
apis: (oI) => {
258337
return {
259338
...oI,
@@ -321,14 +400,10 @@ function initST({ passwordlessConfig } = {}) {
321400
},
322401
resetPasswordUsingTokenFeature: {
323402
createAndSendCustomEmail: (_, passwordResetURLWithToken) => {
403+
console.log(passwordResetURLWithToken);
324404
latestURLWithToken = passwordResetURLWithToken;
325405
},
326406
},
327-
emailVerificationFeature: {
328-
createAndSendCustomEmail: (_, emailVerificationURLWithToken) => {
329-
latestURLWithToken = emailVerificationURLWithToken;
330-
},
331-
},
332407
}),
333408
ThirdParty.init({
334409
signInAndUpFeature: {
@@ -382,6 +457,12 @@ function initST({ passwordlessConfig } = {}) {
382457
signUpFeature: {
383458
formFields,
384459
},
460+
resetPasswordUsingTokenFeature: {
461+
createAndSendCustomEmail: (_, passwordResetURLWithToken) => {
462+
console.log(passwordResetURLWithToken);
463+
latestURLWithToken = passwordResetURLWithToken;
464+
},
465+
},
385466
providers: [
386467
ThirdPartyEmailPassword.Google({
387468
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
@@ -614,6 +695,7 @@ function initST({ passwordlessConfig } = {}) {
614695
},
615696
},
616697
}),
698+
UserRoles.init(),
617699
];
618700

619701
SuperTokens.init({

0 commit comments

Comments
 (0)