public virtual void TestUsingHiddenDeltaBaseFails()
        {
            byte[] delta = new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                            (int)(0x1)), (byte)('c') };
            TestRepository <Repository> s = new TestRepository <Repository>(src);
            RevCommit N = s.Commit().Parent(B).Add("q", s.Blob(BinaryDelta.Apply(dst.Open(b).
                                                                                 GetCachedBytes(), delta))).Create();

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 3);
            Copy(pack, src.Open(N));
            Copy(pack, src.Open(s.ParseBody(N).Tree));
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            b.CopyRawTo(pack);
            Deflate(pack, delta);
            Digest(pack);
            TemporaryBuffer.Heap inBuf     = new TemporaryBuffer.Heap(1024);
            PacketLineOut        inPckLine = new PacketLineOut(inBuf);

            inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s"
                                  + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
            inPckLine.End();
            pack.WriteTo(inBuf, PM);
            TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
            ReceivePack          rp     = new ReceivePack(dst);

            rp.SetCheckReceivedObjects(true);
            rp.SetCheckReferencedObjectsAreReachable(true);
            rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
            try
            {
                Receive(rp, inBuf, outBuf);
                NUnit.Framework.Assert.Fail("Expected UnpackException");
            }
            catch (UnpackException failed)
            {
                Exception err = failed.InnerException;
                NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
                MissingObjectException moe = (MissingObjectException)err;
                NUnit.Framework.Assert.AreEqual(b, moe.GetObjectId());
            }
            PacketLineIn r      = AsPacketLineIn(outBuf);
            string       master = r.ReadString();
            int          nul    = master.IndexOf('\0');

            NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
            NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
                                                (master, 0, nul));
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
            NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + b.Name, r.ReadString
                                                ());
            NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
                                                ());
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
        }
        public virtual void TestUsingUnknownBlobFails()
        {
            // Try to use the 'n' blob that is not on the server.
            //
            TestRepository <Repository> s = new TestRepository <Repository>(src);
            RevBlob   n = s.Blob("n");
            RevCommit N = s.Commit().Parent(B).Add("q", n).Create();

            // But don't include it in the pack.
            //
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 2);
            Copy(pack, src.Open(N));
            Copy(pack, src.Open(s.ParseBody(N).Tree));
            Digest(pack);
            TemporaryBuffer.Heap inBuf     = new TemporaryBuffer.Heap(1024);
            PacketLineOut        inPckLine = new PacketLineOut(inBuf);

            inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s"
                                  + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
            inPckLine.End();
            pack.WriteTo(inBuf, PM);
            TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
            ReceivePack          rp     = new ReceivePack(dst);

            rp.SetCheckReceivedObjects(true);
            rp.SetCheckReferencedObjectsAreReachable(true);
            rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
            try
            {
                Receive(rp, inBuf, outBuf);
                NUnit.Framework.Assert.Fail("Expected UnpackException");
            }
            catch (UnpackException failed)
            {
                Exception err = failed.InnerException;
                NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
                MissingObjectException moe = (MissingObjectException)err;
                NUnit.Framework.Assert.AreEqual(n, moe.GetObjectId());
            }
            PacketLineIn r      = AsPacketLineIn(outBuf);
            string       master = r.ReadString();
            int          nul    = master.IndexOf('\0');

            NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
            NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
                                                (master, 0, nul));
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
            NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + n.Name, r.ReadString
                                                ());
            NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
                                                ());
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
        }
        public virtual void TestCreateBranchAtHiddenCommitFails()
        {
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
            PackHeader(pack, 0);
            Digest(pack);
            TemporaryBuffer.Heap inBuf     = new TemporaryBuffer.Heap(256);
            PacketLineOut        inPckLine = new PacketLineOut(inBuf);

            inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + P.Name + ' ' + "refs/heads/s"
                                  + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
            inPckLine.End();
            pack.WriteTo(inBuf, PM);
            TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
            ReceivePack          rp     = new ReceivePack(dst);

            rp.SetCheckReceivedObjects(true);
            rp.SetCheckReferencedObjectsAreReachable(true);
            rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
            try
            {
                Receive(rp, inBuf, outBuf);
                NUnit.Framework.Assert.Fail("Expected UnpackException");
            }
            catch (UnpackException failed)
            {
                Exception err = failed.InnerException;
                NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
                MissingObjectException moe = (MissingObjectException)err;
                NUnit.Framework.Assert.AreEqual(P, moe.GetObjectId());
            }
            PacketLineIn r      = AsPacketLineIn(outBuf);
            string       master = r.ReadString();
            int          nul    = master.IndexOf('\0');

            NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
            NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
                                                (master, 0, nul));
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
            NUnit.Framework.Assert.AreEqual("unpack error Missing commit " + P.Name, r.ReadString
                                                ());
            NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
                                                ());
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
        }
Exemplo n.º 4
0
            /// <exception cref="System.IO.IOException"></exception>
            internal virtual void SendRequest()
            {
                // Try to compress the content, but only if that is smaller.
                TemporaryBuffer buf = new TemporaryBuffer.Heap(this._enclosing.http.postBuffer);

                try
                {
                    GZIPOutputStream gzip = new GZIPOutputStream(buf);
                    [email protected](gzip, null);
                    gzip.Close();
                    if ([email protected]() < buf.Length())
                    {
                        buf = this.@out;
                    }
                }
                catch (IOException)
                {
                    // Most likely caused by overflowing the buffer, meaning
                    // its larger if it were compressed. Don't compress.
                    buf = this.@out;
                }
                this.OpenStream();
                if (buf != this.@out)
                {
                    this.conn.SetRequestProperty(HttpSupport.HDR_CONTENT_ENCODING, HttpSupport.ENCODING_GZIP
                                                 );
                }
                this.conn.SetFixedLengthStreamingMode((int)buf.Length());
                OutputStream httpOut = this.conn.GetOutputStream();

                try
                {
                    buf.WriteTo(httpOut, null);
                }
                finally
                {
                    httpOut.Close();
                }
            }
Exemplo n.º 5
0
            /// <exception cref="System.IO.IOException"></exception>
            internal virtual void Execute()
            {
                [email protected]();
                if (this.conn == null)
                {
                    // Output hasn't started yet, because everything fit into
                    // our request buffer. Send with a Content-Length header.
                    //
                    if ([email protected]() == 0)
                    {
                        throw new TransportException(this._enclosing.uri, JGitText.Get().startingReadStageWithoutWrittenRequestDataPendingIsNotSupported
                                                     );
                    }
                    // Try to compress the content, but only if that is smaller.
                    TemporaryBuffer buf = new TemporaryBuffer.Heap(this._enclosing.http.postBuffer);
                    try
                    {
                        GZIPOutputStream gzip = new GZIPOutputStream(buf);
                        [email protected](gzip, null);
                        gzip.Close();
                        if ([email protected]() < buf.Length())
                        {
                            buf = this.@out;
                        }
                    }
                    catch (IOException)
                    {
                        // Most likely caused by overflowing the buffer, meaning
                        // its larger if it were compressed. Don't compress.
                        buf = this.@out;
                    }
                    this.OpenStream();
                    if (buf != this.@out)
                    {
                        this.conn.SetRequestProperty(HttpSupport.HDR_CONTENT_ENCODING, HttpSupport.ENCODING_GZIP
                                                     );
                    }
                    this.conn.SetFixedLengthStreamingMode((int)buf.Length());
                    OutputStream httpOut = this.conn.GetOutputStream();
                    try
                    {
                        buf.WriteTo(httpOut, null);
                    }
                    finally
                    {
                        httpOut.Close();
                    }
                }
                [email protected]();
                int status = HttpSupport.Response(this.conn);

                if (status != HttpURLConnection.HTTP_OK)
                {
                    throw new TransportException(this._enclosing.uri, status + " " + this.conn.GetResponseMessage
                                                     ());
                }
                //$NON-NLS-1$
                string contentType = this.conn.GetContentType();

                if (!this.responseType.Equals(contentType))
                {
                    this.conn.GetInputStream().Close();
                    throw this._enclosing.WrongContentType(this.responseType, contentType);
                }
                [email protected](this._enclosing.OpenInputStream(this.conn));
                [email protected](this.execute);
                this.conn = null;
            }