public void TestPkcs8KeyGeneration() { var generator = new JwtGenerator(_mockAppId, _mockPKCS8); var jwt = generator.GenerateJwt(); var decoded = JsonConvert.DeserializeObject <JObject>(generator.DecodeJwt(jwt)); Assert.Equal(_mockAppId, decoded["application_id"].ToString()); }
public void GenerateTokenWithFullAcls() { var generator = new JwtGenerator(_mockAppId, _mockPKCS1, Acls.FullAcls()); var expected = @"{""paths"":{""/*/users/**"":{},""/*/conversations/**"":{},""/*/sessions/**"":{},""/*/devices/**"":{},""/*/image/**"":{},""/*/media/**"":{},""/*/applications/**"":{},""/*/push/**"":{},""/*/knocking/**"":{}}}"; var jwt = generator.GenerateJwt(); var decoded = JsonConvert.DeserializeObject <JObject>(generator.DecodeJwt(jwt)); Assert.Equal(_mockAppId, decoded["application_id"].ToString()); Assert.Equal(expected, Regex.Replace(decoded["acls"].ToString(), @"\s+", "")); }
public void GenerateTokenNoAcls() { var generator = new JwtGenerator(_mockAppId, _mockPKCS1); var jwt = generator.GenerateJwt(); JToken acls; var decoded = JsonConvert.DeserializeObject <JObject>(generator.DecodeJwt(jwt)); Assert.Equal(_mockAppId, decoded["application_id"].ToString()); Assert.False(decoded.TryGetValue("acl", out acls)); }
public void TestSingleAcl() { var expected = @"{""paths"":{""/*/users/**"":{}}}"; var acls = new Acls { Paths = new List <AclPath> { new AclPath { ApiVersion = "*", ResourceType = "users", Resource = "**", AccessLevels = new object() } } }; var generator = new JwtGenerator(_mockAppId, _mockPKCS1, acls); var jwt = generator.GenerateJwt(); var decoded = JsonConvert.DeserializeObject <JObject>(generator.DecodeJwt(jwt)); Assert.Equal(_mockAppId, decoded["application_id"].ToString()); Assert.Equal(expected, Regex.Replace(decoded["acls"].ToString(), @"\s+", "")); }