コード例 #1
0
            internal override ReceivePack CreateReceivePack(Repository db)
            {
                db.Close();
                this._enclosing.dst.IncrementOpen();
                ReceivePack rp = base.CreateReceivePack(this._enclosing.dst);

                rp.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
                return(rp);
            }
コード例 #2
0
        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.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
            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());
        }
コード例 #3
0
        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.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
            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());
        }
コード例 #4
0
        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.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
            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());
        }
コード例 #5
0
 public virtual void TestUsingUnknownTreeFails()
 {
     TestRepository<Repository> s = new TestRepository<Repository>(src);
     RevCommit N = s.Commit().Parent(B).Add("q", s.Blob("a")).Create();
     RevTree t = s.ParseBody(N).Tree;
     // Don't include the tree in the pack.
     //
     TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
     PackHeader(pack, 1);
     Copy(pack, src.Open(N));
     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.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
     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(t, 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 tree " + t.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());
 }
コード例 #6
0
 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.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
     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());
 }
コード例 #7
0
 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.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
     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());
 }