コード例 #1
0
        public void GetsInternalAvcCorrectly()
        {
            //Arrange
            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "DogeCoinFlag";
            json["version"]      = "1.0.0";
            json["download"]     = "https://awesomemod.example/AwesomeMod.zip";

            var sut = new ModuleService();

            // Act
            var result = sut.GetInternalAvc(CkanModule.FromJson(json.ToString()), TestData.DogeCoinFlagAvcZip());

            // Assert
            Assert.That(result, Is.Not.Null,
                        "ModuleService should get an internal AVC file."
                        );
            Assert.That(result.version, Is.EqualTo(new Version("1.1.0")),
                        "ModuleService should get correct version from the internal AVC file."
                        );
            Assert.That(result.ksp_version, Is.EqualTo(new KSPVersion("0.24.2")),
                        "ModuleService should get correct ksp_version from the internal AVC file."
                        );
            Assert.That(result.ksp_version_min, Is.EqualTo(new KSPVersion("0.24.0")),
                        "ModuleService should get correct ksp_version_min from the internal AVC file."
                        );
            Assert.That(result.ksp_version_max, Is.EqualTo(new KSPVersion("0.24.2")),
                        "ModuleService should get correct ksp_version_max from  the internal AVC file."
                        );
        }
コード例 #2
0
ファイル: VrefValidator.cs プロジェクト: net-lisias-kspw/CKAN
        public void Validate(Metadata metadata)
        {
            Log.Info("Validating that metadata vref is consistent with download contents");

            JObject json      = metadata.Json();
            var     noVersion = metadata.Version == null;

            if (noVersion)
            {
                json["version"] = "0";
            }
            var mod = CkanModule.FromJson(json.ToString());

            if (noVersion)
            {
                json.Remove("version");
            }

            if (!mod.IsDLC)
            {
                var zipFilePath = _http.DownloadModule(metadata);
                if (!string.IsNullOrEmpty(zipFilePath))
                {
                    bool hasVref = (metadata.Vref != null);

                    string path        = null;
                    bool   installable = false;
                    try
                    {
                        using (var zipfile = new ZipFile(zipFilePath))
                        {
                            // Pass a regex that matches anything so it returns the first if found
                            var verFileAndInstallable = _moduleService.FindInternalAvc(mod, zipfile, ".");
                            if (verFileAndInstallable != null)
                            {
                                // This will throw if there's a syntax error
                                var avc = ModuleService.GetInternalAvc(zipfile, verFileAndInstallable.Item1);
                                path        = verFileAndInstallable.Item1.Name;
                                installable = verFileAndInstallable.Item2;
                            }
                        }
                    }
                    catch (BadMetadataKraken)
                    {
                        // This means the install stanzas don't match any files.
                        // That's not our problem; someone else will report it.
                    }
                    catch (Kraken)
                    {
                        // If FindInternalAvc throws anything else, then there's a version file with a syntax error.
                        // This shouldn't cause the inflation to fail, but it does deprive us of the path.
                        path        = "";
                        installable = false;
                    }

                    bool hasVersionFile = (path != null);

                    if (hasVref && !hasVersionFile)
                    {
                        Log.Warn("$vref present, version file missing");
                    }
                    else if (!hasVref && hasVersionFile && installable)
                    {
                        Log.WarnFormat("$vref absent, version file present: {0}", path);
                    }
                }
            }
        }