Exemplo n.º 1
0
        public void ValidateSignaturesTest(string testfile)
        {
            Console.WriteLine(testfile);
            string location = testfile;

            if (!testfile.StartsWith("http:") && !testfile.StartsWith("https:"))
            {
                string contents = File.ReadAllText(testfile);
                if (!contents.Contains("<?xml "))
                {
                    // TODO use separate function to identify filetype
                    Console.WriteLine(" not XML data - assuming appref-ms");
                    Console.WriteLine(contents);
                    Assert.EndsWith(".appref-ms", testfile);
                    string newPath = contents.Substring(0, contents.IndexOf("#"));
                    ValidateSignaturesTest(newPath);
                    return;
                }
            }
            bool isApplicationFile = testfile.EndsWith(".application");
            var  asm    = new ClickOnce.Manifest(location, testfile);
            var  depAsm = asm.GetDeployment();

            Assert.Equal(isApplicationFile, depAsm.Install.HasValue);
            HandleManifest(depAsm);
        }
Exemplo n.º 2
0
        public void GenerateApprefMsStringTest(string orgappref)
        {
            Console.WriteLine(orgappref);
            string contents = File.ReadAllText(orgappref);
            string newPath  = contents.Substring(0, contents.IndexOf("#"));
            var    asm      = new ClickOnce.Manifest(newPath);

            Assert.Equal(contents, asm.GenerateApprefMsString());
            byte[] rawBytes = File.ReadAllBytes(orgappref);
            Assert.Equal(rawBytes, asm.GenerateApprefMsBytes());
        }
Exemplo n.º 3
0
        private static void HandleManifest(ClickOnce.Manifest depAsm, string baseLibName = null)
        {
            // for now we don't have any tests where this is false
            Assert.True(depAsm.MapFileExtensions);
            if (baseLibName == null)
            {
                baseLibName = depAsm.LocalLibName();
            }
            Console.WriteLine($" BaseLibName: {baseLibName}");
            Assert.NotNull(baseLibName);
            Assert.NotEmpty(baseLibName);
            //depAsm.VerifySignature();
            ClickOnce.Dependency chainTo = null;
            foreach (var d in depAsm.GetDependencys())
            {
                Console.WriteLine($"+ {d} {d.Size} {d.DependencyType}");
                if (d.Codebase == null)
                {
                    Console.WriteLine($"!! No Codebase skipping");
                    continue;
                }
                if (d.Codebase.EndsWith(".manifest") && chainTo == null)
                {
                    chainTo = d;
                }
                Assert.Contains(".", d.Codebase);
                string remote  = d.RemoteUri();
                string libName = d.LocalLibName() ?? baseLibName;
                Console.WriteLine($"  LibName: {libName} {d.Codebase}");
                Console.WriteLine($"  Remote: {remote}");
                if (remote != null && remote.StartsWith("http"))
                {
                    if (depAsm.Install.HasValue)
                    {
                        Assert.EndsWith(".manifest", remote);
                    }
                    else // this can only be tested when manifest is loaded from application file
                    {
                        Assert.EndsWith(".deploy", remote);
                    }
                }

                Assert.NotNull(libName);
                Assert.NotEmpty(libName);
            }

            if (chainTo != null)
            {
                string remote  = chainTo.RemoteUri();
                string libName = chainTo.LocalLibName() ?? baseLibName;

                string p = Path.Combine(GetTempPath(), libName);
                chainTo.GetToLocalPathAsync(p).
                ContinueWith(t => {
                    if (t.Exception != null)
                    {
                        throw t.Exception.Flatten();
                    }
                    Console.WriteLine($" - OK {t.Result.Replace(GetTempPath(), "...")}");
                    return(t.Result);
                }).Wait();
                string path = chainTo.LastSeenLocalPath;
                Assert.NotNull(path); // we should already have waited

                var app = new ClickOnce.Manifest(remote, path);
                app.MapFileExtensions = depAsm.MapFileExtensions;
                HandleManifest(app, libName);
            }
        }