1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
2.4 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for 'jws.js' utility methods</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/jsbn.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/base64.js"></script>
<script language="JavaScript" type="text/javascript" src="../base64x-1.1.js"></script>
<script language="JavaScript" type="text/javascript" src="../ext/json-sans-eval.js"></script>
<script language="JavaScript" type="text/javascript" src="../jws-3.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
test("isSafeJSONString", function() {
expect(4);
equal(KJUR.jws.JWS.isSafeJSONString("{'aaa':'bbb'}"), 1, "1 - {'aaa':'bbb'}");
equal(KJUR.jws.JWS.isSafeJSONString("{aaa:bbb}"), 1, "1 - {aaa:bbb}");
equal(KJUR.jws.JWS.isSafeJSONString("1234"), 0, "0 - 1234");
equal(KJUR.jws.JWS.isSafeJSONString("'abcd'"), 0, "0 - 'abcd'");
});
test("readSafeJSONString 1", function() {
var a = KJUR.jws.JWS.readSafeJSONString("{\"aaa\":\"bbb\"}");
expect(2);
equal(typeof a, "object", "object");
equal(a.aaa, "bbb", "bbb");
});
test("parse jwt.io sample", function() {
var sJWS = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ";
var result = KJUR.jws.JWS.parse(sJWS);
equal(result.headerObj.alg, "HS256", "headerObj.alg=HS256");
equal(result.headerObj.typ, "JWT", "headerObj.typ=JWT");
equal(result.payloadObj.sub, "1234567890", "payloadObj.sub=1234567890");
equal(result.payloadObj.name, "John Doe", "payloadObj.name=John Doe");
equal(result.payloadObj.admin, true, "payloadObj.admin=true");
equal(result.headerPP, "{\n \"alg\": \"HS256\",\n \"typ\": \"JWT\"\n}", "headerPP");
equal(result.payloadPP, "{\n \"sub\": \"1234567890\",\n \"name\": \"John Doe\",\n \"admin\": true\n}", "payloadPP");
equal(result.sigHex, "4c9540f793ab33b13670169bdf444c1eb1c37047f18e861981e14e34587b1e04", "sigHex");
});
});
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="index.html">TEST INDEX</a> |
</body>
</html>