Example #1
0
        public void Shall_clone_header()
        {
            var original = WwwAuthenticateHeader.Parse("Basic qop=\"auth\"");
            var cloned   = original.DeepClone();

            original.AuthenticationType = "Digest";
            original.QopOptions         = null;
            original.Nonce = "\"abc\"";

            Assert.That(cloned.ToString(), Is.EqualTo("Basic  qop=\"auth\""));
            Assert.That(original.ToString(), Is.EqualTo("Digest  nonce=\"abc\""));
        }
Example #2
0
        public void Shall_parse_header()
        {
            const string str =
                "Basic realm=\"a\", domain=\"b\", nonce=\"c\", opaque=\"d\", stale=\"e\", algorithm=\"f\", " +
                "qop=\"g\", version=\"h\", targetname=\"i\", gssapi-data=\"j\"";

            Assert.That(WwwAuthenticateHeader.TryParse(str, out WwwAuthenticateHeader header), Is.True);
            Assert.That(header.AuthenticationType, Is.EqualTo("Basic"));
            Assert.That(header.Realm, Is.EqualTo("\"a\""));
            Assert.That(header.Domain, Is.EqualTo("\"b\""));
            Assert.That(header.Nonce, Is.EqualTo("\"c\""));
            Assert.That(header.Opaque, Is.EqualTo("\"d\""));
            Assert.That(header.Stale, Is.EqualTo("\"e\""));
            Assert.That(header.Algorithm, Is.EqualTo("\"f\""));
            Assert.That(header.QopOptions, Is.EqualTo("\"g\""));
            Assert.That(header.Version, Is.EqualTo("\"h\""));
            Assert.That(header.TargetName, Is.EqualTo("\"i\""));
            Assert.That(header.GssApiData, Is.EqualTo("\"j\""));
        }
Example #3
0
        public void Shall_stringify_header()
        {
            var header = new WwwAuthenticateHeader
            {
                AuthenticationType = "Basic",
                Realm      = "\"a\"",
                Domain     = "\"b\"",
                Nonce      = "\"c\"",
                Opaque     = "\"d\"",
                Stale      = "\"e\"",
                Algorithm  = "\"f\"",
                QopOptions = "\"g\"",
                Version    = "\"h\"",
                TargetName = "\"i\"",
                GssApiData = "\"j\""
            };

            Assert.That(
                header.ToString(),
                Is.EqualTo(
                    "Basic realm=\"a\", domain=\"b\", nonce=\"c\", opaque=\"d\", stale=\"e\", algorithm=\"f\", " +
                    "qop=\"g\", version=\"h\", targetname=\"i\", gssapi-data=\"j\""));
        }
Example #4
0
        public void Shall_byteify_request()
        {
            var request = new SipRequest
            {
                Version     = "SIP/2.0",
                Method      = "INVITE",
                RequestUri  = SipUri.Parse("sip:[email protected]"),
                From        = NameAddressHeader.Parse("John Smith <sip:[email protected]>"),
                To          = NameAddressHeader.Parse("Joe Shmoe <sip:[email protected]>"),
                CallId      = CallIdHeader.Parse("*****@*****.**"),
                CSeq        = CSeqHeader.Parse("1 INVITE"),
                ContentType = ContentTypeHeader.Parse("text/plain"),
                MimeVersion = ContentLengthHeader.Parse("1.0")
            };

            request.Vias.Add(ViaHeader.Parse("SIP/2.0/UDP foo.bar.com"));
            request.RecordRoutes.Add(NameAddressHeader.Parse("Tommy Atkins <sip:[email protected]>"));
            request.Routes.Add(NameAddressHeader.Parse("John Doe <sip:[email protected]>"));
            request.Contacts.Add(NameAddressHeader.Parse("Prisoner X <sip:[email protected]>"));
            request.Authorizations.Add(AuthorizationHeader.Parse("Digest username=\"Alice\""));
            request.WwwAuthenticates.Add(WwwAuthenticateHeader.Parse("Digest realm=\"abc.com\""));
            request.ProxyAuthenticates.Add(WwwAuthenticateHeader.Parse("Digest realm=\"xyz.com\""));
            request.ProxyAuthorizations.Add(AuthorizationHeader.Parse("Digest username=\"Bob\""));
            request.CallInfos.Add(CallInfoHeader.Parse("<http://www.abc.com/photo.png>;purpose=icon"));
            request.Allows.Add(ContentLengthHeader.Parse("INVITE, ACK, BYE"));
            request.ContentEncodings.Add(ContentLengthHeader.Parse("deflate"));
            request.AlertInfos.Add(CallInfoHeader.Parse("<http://www.abc.com/sound.wav>"));
            request.ErrorInfos.Add(CallInfoHeader.Parse("<sip:[email protected]>"));
            request.Accepts.Add(ContentTypeHeader.Parse("application/sdp"));
            request.AcceptEncodings.Add(AcceptEncodingHeader.Parse("gzip"));
            request.AcceptLanguages.Add(AcceptEncodingHeader.Parse("en"));
            request.AuthenticationInfos.Add(AuthenticationInfoHeader.Parse("nextnonce=\"abc\""));
            request.ProxyAuthenticationInfos.Add(AuthenticationInfoHeader.Parse("nextnonce=\"def\""));
            request.OtherHeaders.Add(new GenericHeader("P-Asserted-Identity", "sip:[email protected]"));
            request.Bodies.Add(SipBody.Parse("Hello world!"));

            var buffer  = new byte[ushort.MaxValue];
            var success = request.TryCopyTo(buffer, 0, out int length);

            Assert.That(success, Is.True);

            var request2 = SipMessage.Parse(new ArraySegment <byte>(buffer, 0, length));

            Assert.That(request2.ToString(), Is.EqualTo(
                            "INVITE sip:[email protected] SIP/2.0\r\n" +
                            "Via: SIP/2.0/UDP foo.bar.com\r\n" +
                            "Record-Route: Tommy Atkins <sip:[email protected]>\r\n" +
                            "Route: John Doe <sip:[email protected]>\r\n" +
                            "From: John Smith <sip:[email protected]>\r\n" +
                            "To: Joe Shmoe <sip:[email protected]>\r\n" +
                            "Call-ID: [email protected]\r\n" +
                            "CSeq: 1 INVITE\r\n" +
                            "Contact: Prisoner X <sip:[email protected]>\r\n" +
                            "Authorization: Digest username=\"Alice\"\r\n" +
                            "WWW-Authenticate: Digest realm=\"abc.com\"\r\n" +
                            "Proxy-Authenticate: Digest realm=\"xyz.com\"\r\n" +
                            "Proxy-Authorization: Digest username=\"Bob\"\r\n" +
                            "Call-Info: <http://www.abc.com/photo.png>;purpose=icon\r\n" +
                            "Content-Type: text/plain\r\n" +
                            "Mime-Version: 1.0\r\n" +
                            "Allow: INVITE\r\n" +
                            "Allow: ACK\r\n" +
                            "Allow: BYE\r\n" +
                            "Content-Encoding: deflate\r\n" +
                            "Alert-Info: <http://www.abc.com/sound.wav>\r\n" +
                            "Error-Info: <sip:[email protected]>\r\n" +
                            "Accept: application/sdp\r\n" +
                            "Accept-Encoding: gzip\r\n" +
                            "Accept-Language: en\r\n" +
                            "Authentication-Info: nextnonce=\"abc\"\r\n" +
                            "Proxy-Authentication-Info: nextnonce=\"def\"\r\n" +
                            "P-asserted-identity: sip:[email protected]\r\n" +
                            "Content-Length:    12\r\n" +
                            "\r\n" +
                            "Hello world!"));
        }