def check_allowed(alg, key):
@Vows.batch<EOL>class GenerateJWT(Vows.Context):<EOL><INDENT>"""<STR_LIT>"""<EOL>def topic(self):<EOL><INDENT>"""<STR_LIT>"""<EOL>return jwt.generate_jwt(payload, key, alg, timedelta(seconds=<NUM_LIT>))<EOL><DEDENT>class VerifyJWTNoAlgsSpecified(Vows.Context):<EOL><INDENT>"""<STR_LIT>"""<EOL>@Vows.capture_error<EOL>def topic(self, topic):<EOL><INDENT>"""<STR_LIT>"""<EOL>return jwt.verify_jwt(topic, key)<EOL><DEDENT>def token_should_not_verify(self, r):<EOL><INDENT>"""<STR_LIT>"""<EOL>expect(r).to_be_an_error()<EOL>expect(str(r)).to_equal('<STR_LIT>' + alg)<EOL><DEDENT><DEDENT>class VerifyJWTAllAlgsAllowed(Vows.Context):<EOL><INDENT>"""<STR_LIT>"""<EOL>def topic(self, topic):<EOL><INDENT>"""<STR_LIT>"""<EOL>return jwt.verify_jwt(topic, key, all_algs)<EOL><DEDENT>def token_should_verify(self, r):<EOL><INDENT>"""<STR_LIT>"""<EOL>expect(r).to_be_instance_of(tuple)<EOL>header, _ = r<EOL>expect(header).to_equal({'<STR_LIT>': alg, '<STR_LIT>': '<STR_LIT>'})<EOL><DEDENT><DEDENT>class VerifyJWTNoAlgsAllowed(Vows.Context):<EOL><INDENT>"""<STR_LIT>"""<EOL>@Vows.capture_error<EOL>def topic(self, topic):<EOL><INDENT>"""<STR_LIT>"""<EOL>return jwt.verify_jwt(topic, key, [])<EOL><DEDENT>def token_should_not_verify(self, r):<EOL><INDENT>"""<STR_LIT>"""<EOL>expect(r).to_be_an_error()<EOL>expect(str(r)).to_equal('<STR_LIT>' + alg)<EOL><DEDENT><DEDENT>class VerifyJWTAlgNotAllowed(Vows.Context):<EOL><INDENT>"""<STR_LIT>"""<EOL>@Vows.capture_error<EOL>def topic(self, topic):<EOL><INDENT>"""<STR_LIT>"""<EOL>return jwt.verify_jwt(topic, key, [a for a in all_algs if a != alg])<EOL><DEDENT>def token_should_not_verify(self, r):<EOL><INDENT>"""<STR_LIT>"""<EOL>expect(r).to_be_an_error()<EOL>expect(str(r)).to_equal('<STR_LIT>' + alg)<EOL><DEDENT><DEDENT>class VerifyJWTAlgAllowed(Vows.Context):<EOL><INDENT>"""<STR_LIT>"""<EOL>@Vows.capture_error<EOL>def topic(self, topic):<EOL><INDENT>"""<STR_LIT>"""<EOL>return jwt.verify_jwt(topic, key, [alg])<EOL><DEDENT>def token_should_verify(self, r):<EOL><INDENT>"""<STR_LIT>"""<EOL>expect(r).to_be_instance_of(tuple)<EOL>header, _ = r<EOL>expect(header).to_equal({'<STR_LIT>': alg, '<STR_LIT>': '<STR_LIT>'})<EOL><DEDENT><DEDENT>class VerifyJWTWrongType(Vows.Context):<EOL><INDENT>"""<STR_LIT>"""<EOL>@Vows.capture_error<EOL>def topic(self, topic):<EOL><INDENT>"""<STR_LIT>"""<EOL>return jwt.verify_jwt(topic, key, {alg: True})<EOL><DEDENT>def token_should_verify(self, r):<EOL><INDENT>"""<STR_LIT>"""<EOL>expect(r).to_be_an_error()<EOL>expect(str(r)).to_equal('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>
setup tests