Exemplo n.º 1
0
        public void TestGenerateTarGzNoDirectory()
        {
            string nonexistantdir = Path.Combine(tempFolder, "temp");

            Utils.GenerateTarGz(nonexistantdir, null, null);
            Assert.Fail("Expected an IOException as the directory does not exist");
        }
Exemplo n.º 2
0
        public void TestGenerateDirectoryHashNoDirectory()
        {
            string nonExistentDir = Path.Combine(Path.GetFullPath(tempFolder), "temsp");

            Utils.GenerateDirectoryHash(null, nonExistentDir, "");
            Assert.Fail("Expected an IOException as the directory does not exist");
        }
Exemplo n.º 3
0
 public void TestCheckGrpcUrlInvalid()
 {
     // Test a number of invalid variations
     Assert.IsNotNull(Utils.CheckGrpcUrl("http://hyperledger.org:1234"));
     Assert.IsNotNull(Utils.CheckGrpcUrl("grpc://hyperledger.org"));
     Assert.IsNotNull("grpc://hyperledger.org:1234/index.html");
 }
Exemplo n.º 4
0
        public void TestGenerateDirectoryHashEmptyDirectory()
        {
            string emptydir = Path.Combine(tempFolder, "subfolder");

            Directory.CreateDirectory(emptydir);
            Utils.GenerateDirectoryHash(null, emptydir, "");
            Assert.Fail("Expected an IOException as the directory is empty");
        }
Exemplo n.º 5
0
        public void TestHash()
        {
            byte[] input        = "TheQuickBrownFox".ToBytes();
            string expectedHash = "feb69c5c360a15802de6af23a3f5622da9d96aff2be78c8f188cce57a3549db6";

            byte[] hash = Utils.Hash(input, new Sha3Digest());
            Assert.AreEqual(expectedHash, hash.ToHexString());
        }
Exemplo n.º 6
0
        public void TestDeleteFileOrDirectoryFile()
        {
            string tempfile = Path.Combine(tempFolder, "temp.txt");

            File.OpenWrite(tempfile).Close();
            Assert.IsTrue(File.Exists(tempfile));
            Utils.DeleteFileOrDirectory(tempfile);
            Assert.IsFalse(File.Exists(tempfile));
        }
Exemplo n.º 7
0
        public void TestGenerateDirectoryHashWithFile()
        {
            // Create a temp file
            string tempfile = Path.Combine(tempFolder, "temp.txt");

            File.OpenWrite(tempfile).Close();
            Utils.GenerateDirectoryHash(null, tempfile, "");
            Assert.Fail("Expected an IOException as we passed it a file");
        }
Exemplo n.º 8
0
        public void TestGenerateParameterHash()
        {
            List <string> args = new List <string>();

            args.Add("a");
            args.Add("b");
            string hash = Utils.GenerateParameterHash("mypath", "myfunc", args);

            Assert.AreEqual(Utils.Hash("mypathmyfuncab".ToBytes(), new Sha3Digest()).ToHexString(), hash);
        }
Exemplo n.º 9
0
        public void TestParseGrpcUrl()
        {
            string url = "grpc://hyperledger.org:1234";

            (string Protocol, string Host, int Port) = Utils.ParseGrpcUrl(url);

            Assert.AreEqual("grpc", Protocol);
            Assert.AreEqual("hyperledger.org", Host);
            Assert.AreEqual(1234, Port);
        }
Exemplo n.º 10
0
        private string GrpcTLSify(string location)
        {
            location = location.Trim();
            System.Exception e = Utils.CheckGrpcUrl(location);
            if (e != null)
            {
                throw new System.Exception($"Bad TEST parameters for grpc url {location}");
            }

            return(runningFabricTLS ? Regex.Replace(location, "^grpc://", "grpcs://") : location);
        }
Exemplo n.º 11
0
        public void TestGenerateNonce()
        {
            // As this is a "unique" identifier, we call the function twice to
            // ensure it doesn't return the same value
            byte[] nonce1 = Utils.GenerateNonce();
            byte[] nonce2 = Utils.GenerateNonce();

            Assert.IsNotNull(nonce1);
            Assert.IsNotNull(nonce2);
            Assert.AreNotEqual(nonce1, nonce2, "generateNonce returned a duplicate nonce!");
        }
Exemplo n.º 12
0
        public void TestGenerateUUID()
        {
            // As this is a "unique" identifier, we call the function twice to
            // ensure it doesn't return the same value
            string uuid1 = Utils.GenerateUUID();
            string uuid2 = Utils.GenerateUUID();

            Assert.IsNotNull(uuid1);
            Assert.IsNotNull(uuid2);
            Assert.AreNotEqual(uuid1, uuid2, "gererateUUID returned a duplicate UUID!");
        }
Exemplo n.º 13
0
        public void TestGenerateTarGz()
        {
            // create a temp directory with some files in it
            string tempDir = CreateTempDirWithFiles();

            // Compress
            byte[] data = Utils.GenerateTarGz(tempDir, "newPath", null);

            // Here, we simply ensure that it did something!
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length > 0);
        }
Exemplo n.º 14
0
        public void TestGenerateTarGzEmptyDirectory()
        {
            // create an empty directory
            string emptydir = Path.Combine(tempFolder, "subfolder");

            Directory.CreateDirectory(emptydir);
            byte[] data = Utils.GenerateTarGz(emptydir, null, null);

            // Here, we simply ensure that it did something!
            Assert.IsNotNull(data);
            Assert.IsTrue(data.Length > 0);
        }
Exemplo n.º 15
0
        public void TestDeleteFileOrDirectoryDirectory()
        {
            // create a temp directory with some files in it
            string tempDir = CreateTempDirWithFiles();

            // Ensure the dir exists
            Assert.IsTrue(Directory.Exists(tempDir));

            Utils.DeleteFileOrDirectory(tempDir);

            // Ensure the file was deleted
            Assert.IsFalse(Directory.Exists(tempDir));
        }
Exemplo n.º 16
0
        public void TestGenerateTarGzNOMETAINF()
        {
            List <string> expect = new List <string> {
                "src/github.com/example_cc/example_cc.go"
            };

            string path = Path.Combine(SAMPLE_GO_CC, "/src/github.com/example_cc").Locate();

            byte[] bytes = Utils.GenerateTarGz(path, "src/github.com/", null);
            Assert.IsNotNull(bytes, "generateTarGz() returned null bytes.");
            List <string> tarBytesToEntryArrayList = TestUtils.TestUtils.TarBytesToEntryArrayList(bytes);

            CollectionAssert.AreEquivalent(expect, tarBytesToEntryArrayList, "Tar not what expected.");
        }
Exemplo n.º 17
0
        public void TestGenerateTarGzMETAINF()
        {
            List <string> expect = new List <string> {
                "META-INF/statedb/couchdb/indexes/MockFakeIndex.json", "src/github.com/example_cc/example_cc.go"
            };

            expect.Sort();
            string path    = Path.Combine(SAMPLE_GO_CC, "/src/github.com/example_cc").Locate();
            string metainf = "fixture/meta-infs/test1/META-INF".Locate();

            byte[] bytes = Utils.GenerateTarGz(path, "src/github.com/example_cc", metainf);
            Assert.IsNotNull(bytes, "generateTarGz() returned null bytes.");
            List <string> tarBytesToEntryArrayList = TestUtils.TestUtils.TarBytesToEntryArrayList(bytes);

            CollectionAssert.AreEquivalent(expect, tarBytesToEntryArrayList, "Tar not what expected.");
        }
Exemplo n.º 18
0
        // ==========================================================================================
        // Helper methods
        // ==========================================================================================

        // Helper method to allow tests of multiple code paths through generateDirectoryHash
        public void DoGenerateDirectoryHash(bool useRootDir, bool usePreviousHash)
        {
            // Use any old hash value
            string previousHashToUse = "3c08029b52176eacf802dee93129a9f1fd115008950e1bb968465dcd51bbbb9d";

            // The hashes expected when we 1: do not pass a previousHash and 2: pass
            // the previousHash
            string expectedHash1 = "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a";
            string expectedHash2 = "6c9f96b2dd87d7a02fd3b7cc6026a6a96d21c4c53aaf5777439151690c48c7b8";
            string expectedHash  = usePreviousHash ? expectedHash2 : expectedHash1;

            string chaincodeSubDirString = "chaincode/example/java";

            // Create the temp directories
            string rootDir      = Path.GetFullPath(tempFolder);
            string chaincodeDir = Path.Combine(rootDir, chaincodeSubDirString);

            Directory.CreateDirectory(chaincodeDir);

            string rootDirString = null;
            string chaincodeDirString;

            if (useRootDir)
            {
                // Pass both a RootDir and a chaincodeDir to the function

                rootDirString      = rootDir;
                chaincodeDirString = chaincodeSubDirString;
            }
            else
            {
                // Pass just a chaincodeDir to the function
                chaincodeDirString = chaincodeDir;
            }

            // Create a dummy file in the chaincode directory

            string tempfile = Path.Combine(tempFolder, "temp.txt");

            File.OpenWrite(tempfile).Close();

            string previousHash = usePreviousHash ? previousHashToUse : "";

            string hash = Utils.GenerateDirectoryHash(rootDirString, chaincodeDirString, previousHash);

            Assert.AreEqual(expectedHash, hash);
        }
Exemplo n.º 19
0
 public void TestCheckGrpcUrlValid()
 {
     // Test a number of valid variations
     Assert.IsNull(Utils.CheckGrpcUrl("grpc://hyperledger.org:1234"));
     Assert.IsNull(Utils.CheckGrpcUrl("grpcs://127.0.0.1:1234"));
 }
Exemplo n.º 20
0
 public void TestGenerateTimestamp()
 {
     Assert.IsNotNull(Utils.GenerateTimestamp());
 }