public void TestDecodeUnknown() { EncryptMessage msg = new EncryptMessage(); msg.AddAttribute(HeaderKeys.Algorithm, AlgorithmValues.AES_GCM_128, Attributes.PROTECTED); // msg.AddAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attributes.PROTECTED); msg.SetContent(rgbContent); CBORObject obj = CBORObject.NewMap(); obj.Add("kty", "oct"); obj.Add("k", Encoding.UTF8.GetString(Base64.Encode(rgbKey128))); JWK key = new JWK(obj); Recipient recipient = new Recipient(key, "dir"); msg.AddRecipient(recipient); string rgbMsg = msg.Encode(); JoseException e = Assert.ThrowsException <JoseException>(() => msg = (EncryptMessage)Message.DecodeFromString(rgbMsg)); Assert.AreEqual(e.Message, ("Message was not tagged and no default tagging option given")); }
public void ContentErrors() { CBORObject test = CBORObject.NewMap(); // Empty message - we default to a signed message JoseException e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromJSON(test) ); Assert.AreEqual("field 'signatures' must be present.", e.Message); // Cipher field is not base64 test.Add("ciphertext", " **}"); FormatException format = Assert.ThrowsException <FormatException>(() => Message.DecodeFromJSON(test) ); Assert.AreEqual("The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.", format.Message); // Add the ciphertext field test["ciphertext"] = CBORObject.FromObject("ABCD"); e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromJSON(test) ); Assert.AreEqual("One of protected, unprotected or headers must be present for every recipient", e.Message); // Add an wrong empty recipients structure test.Add("recipients", CBORObject.NewMap()); e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromJSON(test) ); Assert.AreEqual("field 'recipients' must be a non-empty array", e.Message); test["recipients"] = CBORObject.NewArray(); e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromJSON(test) ); Assert.AreEqual("field 'recipients' must be a non-empty array", e.Message); test["recipients"].Add(CBORObject.NewArray()); e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromJSON(test) ); Assert.AreEqual("recipient must be a map", e.Message); test["recipients"][0] = CBORObject.NewMap(); Message.DecodeFromJSON(test); }
public void TestBadDotCount() { JoseException e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromString("This string has no dots in it")); Assert.AreEqual(e.Message, "There are not the correct number of dots."); e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromString("This string has one. dots in it")); Assert.AreEqual(e.Message, "There are not the correct number of dots."); e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromString("This. string has three. dots in. it")); Assert.AreEqual(e.Message, "There are not the correct number of dots."); e = Assert.ThrowsException <JoseException>(() => Message.DecodeFromString("This. string. has. six. dots. in. it")); Assert.AreEqual(e.Message, "There are not the correct number of dots."); }