public CoreRunLibTests(BaseFixture baseFixture) { _baseFixture = baseFixture; _snapFilesystem = new SnapFilesystem(); _snapCryptoProvider = new SnapCryptoProvider(); _snapEmbeddedResources = new SnapEmbeddedResources(); _coreRunLibDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _snapFilesystem); }
public SnapPackageManagerRestoreStrategyInstallOrUpdateTests(BaseFixturePackaging baseFixturePackaging, BaseFixtureNuget baseFixtureNuget) { _nugetServiceMock = new Mock <INugetService>(); _coreRunLibMock = new Mock <ICoreRunLib>(); _snapHttpClientMock = new Mock <ISnapHttpClient>(); _baseFixturePackaging = baseFixturePackaging; _baseFixtureNuget = baseFixtureNuget; _snapFilesystem = new SnapFilesystem(); _snapCryptoProvider = new SnapCryptoProvider(); _snapAppWriter = new SnapAppWriter(); _snapAppReader = new SnapAppReader(); _snapEmbeddedResources = new SnapEmbeddedResources(); _snapPack = new SnapPack(_snapFilesystem, _snapAppReader, _snapAppWriter, _snapCryptoProvider, _snapEmbeddedResources); _snapExtractor = new SnapExtractor(_snapFilesystem, _snapPack, _snapEmbeddedResources); _snapPackageManager = new SnapPackageManager(_snapFilesystem, new SnapOsSpecialFoldersUnix(), _nugetServiceMock.Object, _snapHttpClientMock.Object, _snapCryptoProvider, _snapExtractor, _snapAppReader, _snapPack); _releaseBuilderContext = new SnapReleaseBuilderContext(_coreRunLibMock.Object, _snapFilesystem, _snapCryptoProvider, _snapEmbeddedResources, _snapPack); }
public SnapPackageManagerTests(BaseFixturePackaging baseFixturePackaging, BaseFixtureNuget baseFixtureNuget, ITestOutputHelper testOutputHelper) { _nugetServiceMock = new Mock <INugetService>(); _coreRunLibMock = new Mock <ICoreRunLib>(); _snapHttpClientMock = new Mock <ISnapHttpClient>(); _baseFixturePackaging = baseFixturePackaging; _baseFixtureNuget = baseFixtureNuget; _testOutputHelper = testOutputHelper; _snapFilesystem = new SnapFilesystem(); _snapCryptoProvider = new SnapCryptoProvider(); _snapAppWriter = new SnapAppWriter(); _snapAppReader = new SnapAppReader(); _snapEmbeddedResources = new SnapEmbeddedResources(); _snapPack = new SnapPack(_snapFilesystem, _snapAppReader, _snapAppWriter, _snapCryptoProvider, _snapEmbeddedResources, new SnapBinaryPatcher()); _snapExtractor = new SnapExtractor(_snapFilesystem, _snapPack, _snapEmbeddedResources); _snapPackageManager = new SnapPackageManager(_snapFilesystem, new SnapOsSpecialFoldersUnitTest(_snapFilesystem, _baseFixturePackaging.WorkingDirectory), _nugetServiceMock.Object, _snapHttpClientMock.Object, _snapCryptoProvider, _snapExtractor, _snapAppReader, _snapPack); _releaseBuilderContext = new SnapReleaseBuilderContext(_coreRunLibMock.Object, _snapFilesystem, _snapCryptoProvider, _snapEmbeddedResources, _snapPack); }
internal void AssertChecksums([NotNull] SnapApp snapApp, [NotNull] SnapRelease snapRelease, [NotNull] List <string> extractedFiles) { if (snapApp == null) { throw new ArgumentNullException(nameof(snapApp)); } if (snapRelease == null) { throw new ArgumentNullException(nameof(snapRelease)); } if (extractedFiles == null) { throw new ArgumentNullException(nameof(extractedFiles)); } var nupkgAbsoluteFilename = SnapFilesystem.PathCombine(SnapAppPackagesDirectory, snapRelease.Filename); Assert.True(SnapFilesystem.FileExists(nupkgAbsoluteFilename)); using var packageArchiveReader = new PackageArchiveReader(nupkgAbsoluteFilename); Assert.Equal(snapApp.ReleaseNotes, snapRelease.ReleaseNotes); foreach (var releaseChecksum in snapRelease.Files) { var(_, _, checksumFileAbsolutePath) = NormalizePath(snapRelease, releaseChecksum.NuspecTargetPath); Assert.NotNull(checksumFileAbsolutePath); if (snapRelease.IsDelta) { var deletedChecksum = snapRelease.Deleted.SingleOrDefault(x => x == releaseChecksum.NuspecTargetPath); if (deletedChecksum != null) { Assert.False(SnapFilesystem.FileExists(checksumFileAbsolutePath)); continue; } var unmodifiedChecksum = snapRelease.Unmodified.SingleOrDefault(x => x == releaseChecksum.NuspecTargetPath); if (unmodifiedChecksum != null) { Assert.False(SnapFilesystem.FileExists(checksumFileAbsolutePath)); continue; } } Assert.True(SnapFilesystem.FileExists(checksumFileAbsolutePath)); using var fileStream = SnapFilesystem.FileRead(checksumFileAbsolutePath); var diskSha256Checksum = SnapCryptoProvider.Sha256(fileStream); var diskFilesize = SnapFilesystem.FileStat(checksumFileAbsolutePath).Length; SnapReleaseChecksum targetChecksum; bool useFullChecksum; if (snapRelease.IsFull) { targetChecksum = releaseChecksum; useFullChecksum = true; goto checksum; } if (SnapPack.NeverGenerateBsDiffsTheseAssemblies.Any(x => x == releaseChecksum.NuspecTargetPath)) { targetChecksum = releaseChecksum; useFullChecksum = true; goto checksum; } targetChecksum = snapRelease.New.SingleOrDefault(x => x.NuspecTargetPath == releaseChecksum.NuspecTargetPath); if (targetChecksum != null) { useFullChecksum = true; } else { targetChecksum = snapRelease.Modified.SingleOrDefault(x => x.NuspecTargetPath == releaseChecksum.NuspecTargetPath); useFullChecksum = false; } checksum: Assert.NotNull(targetChecksum); var expectedChecksum = useFullChecksum ? targetChecksum.FullSha256Checksum : targetChecksum.DeltaSha256Checksum; var expectedFilesize = useFullChecksum ? targetChecksum.FullFilesize : targetChecksum.DeltaFilesize; Assert.NotNull(expectedChecksum); if (expectedChecksum == SnapConstants.Sha256EmptyFileChecksum) { Assert.Equal(0, expectedFilesize); } else { Assert.True(expectedFilesize > 0); } Assert.Equal(expectedChecksum, diskSha256Checksum); Assert.Equal(expectedFilesize, diskFilesize); } var snapReleaseChecksum = SnapCryptoProvider.Sha256(snapRelease, packageArchiveReader, SnapPack); var snapReleaseFilesize = SnapFilesystem.FileStat(nupkgAbsoluteFilename)?.Length; var expectedReleaseChecksum = snapRelease.IsFull ? snapRelease.FullSha256Checksum : snapRelease.DeltaSha256Checksum; var expectedReleaseFilesize = snapRelease.IsFull ? snapRelease.FullFilesize : snapRelease.DeltaFilesize; Assert.Equal(expectedReleaseChecksum, snapReleaseChecksum); Assert.Equal(expectedReleaseFilesize, snapReleaseFilesize); }
static int MainImplAsync([NotNull] string[] args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } using var cts = new CancellationTokenSource(); ISnapOs snapOs; try { snapOs = SnapOs.AnyOs; } catch (PlatformNotSupportedException) { SnapLogger.Error($"Platform is not supported: {RuntimeInformation.OSDescription}"); return(1); } catch (Exception e) { SnapLogger.ErrorException("Exception thrown while initializing snap os", e); return(1); } snapOs.InstallExitSignalHandler(async() => { cts.Cancel(); await OnExitAsync(); }); var workingDirectory = Environment.CurrentDirectory; if (!workingDirectory.EndsWith(snapOs.Filesystem.DirectorySeparator)) { workingDirectory += snapOs.Filesystem.DirectorySeparator; } var toolWorkingDirectory = snapOs.Filesystem.PathGetDirectoryName(typeof(Program).Assembly.Location); var snapCryptoProvider = new SnapCryptoProvider(); var snapEmbeddedResources = new SnapEmbeddedResources(); snapEmbeddedResources.ExtractCoreRunLibAsync(snapOs.Filesystem, snapCryptoProvider, toolWorkingDirectory, snapOs.OsPlatform).GetAwaiter().GetResult(); var snapXEmbeddedResources = new SnapxEmbeddedResources(); var coreRunLib = new CoreRunLib(snapOs.Filesystem, snapOs.OsPlatform, toolWorkingDirectory); var snapAppReader = new SnapAppReader(); var snapAppWriter = new SnapAppWriter(); var snapPack = new SnapPack(snapOs.Filesystem, snapAppReader, snapAppWriter, snapCryptoProvider, snapEmbeddedResources); var snapExtractor = new SnapExtractor(snapOs.Filesystem, snapPack, snapEmbeddedResources); var snapSpecsReader = new SnapAppReader(); var snapNetworkTimeProvider = new SnapNetworkTimeProvider("time.cloudflare.com", 123); var snapHttpClient = new SnapHttpClient(new HttpClient()); var nugetServiceCommandPack = new NugetService(snapOs.Filesystem, new NugetLogger(SnapPackLogger)); var nugetServiceCommandPromote = new NugetService(snapOs.Filesystem, new NugetLogger(SnapPromoteLogger)); var nugetServiceCommandDemote = new NugetService(snapOs.Filesystem, new NugetLogger(SnapDemoteLogger)); var nugetServiceCommandRestore = new NugetService(snapOs.Filesystem, new NugetLogger(SnapRestoreLogger)); var nugetServiceNoopLogger = new NugetService(snapOs.Filesystem, new NugetLogger(new LogProvider.NoOpLogger())); var snapPackageRestorer = new SnapPackageManager(snapOs.Filesystem, snapOs.SpecialFolders, nugetServiceCommandPack, snapHttpClient, snapCryptoProvider, snapExtractor, snapAppReader, snapPack); var distributedMutexClient = new DistributedMutexClient(new JsonServiceClient("https://snapx.dev")); Console.CancelKeyPress += async(sender, eventArgs) => { eventArgs.Cancel = !cts.IsCancellationRequested; cts.Cancel(); await OnExitAsync(); }; return(MainAsync(args, coreRunLib, snapOs, snapExtractor, snapOs.Filesystem, snapSpecsReader, snapCryptoProvider, snapPack, snapAppWriter, snapXEmbeddedResources, snapPackageRestorer, snapNetworkTimeProvider, nugetServiceCommandPack, nugetServiceCommandPromote, nugetServiceCommandDemote, nugetServiceCommandRestore, nugetServiceNoopLogger, distributedMutexClient, toolWorkingDirectory, workingDirectory, cts.Token)); }