fix: allow unknown fields (#2640)

This commit is contained in:
Wyatt Johnson
2019-10-16 22:52:33 +00:00
committed by Kim Gardner
parent b38a4f117b
commit d169d3dd51
2 changed files with 22 additions and 1 deletions
@@ -1,5 +1,6 @@
import {
isSSOToken,
SSOTokenSchema,
SSOUserProfileSchema,
} from "coral-server/app/middleware/passport/strategies/verifiers/sso";
import { validate } from "coral-server/app/request/body";
@@ -51,4 +52,24 @@ describe("SSOUserProfileSchema", () => {
expect(validate(SSOUserProfileSchema, profile)).toEqual(profile);
expect(isSSOToken({ user: profile })).toEqual(true);
});
it("allows unknown claims", async () => {
const extra = {
preferred_username: "username",
};
const base = {
user: {
id: "id",
email: "email",
username: "username",
},
};
const token = {
...extra,
...base,
};
expect(validate(SSOTokenSchema, token)).toEqual(base);
expect(isSSOToken(token)).toEqual(true);
});
});
@@ -49,7 +49,7 @@ export interface SSOToken {
}
export function isSSOToken(token: SSOToken | object): token is SSOToken {
const { error } = Joi.validate(token, SSOTokenSchema);
const { error } = Joi.validate(token, SSOTokenSchema, { allowUnknown: true });
return isNil(error);
}