public FactBase() { _symbolService = new Mock <ISymbolsValidatorService>(); _validatorStateService = new Mock <IValidatorStateService>(); _logger = new Mock <ILogger <SymbolsValidatorMessageHandler> >(); _message = new SymbolsValidatorMessage(Guid.NewGuid(), 42, "TestPackage", "1.1.1", "url"); }
public async Task <IValidationResult> ValidateSymbolsAsync(SymbolsValidatorMessage message, CancellationToken token) { _logger.LogInformation("{ValidatorName} :Start ValidateSymbolsAsync. PackageId: {packageId} PackageNormalizedVersion: {packageNormalizedVersion}", ValidatorName.SymbolsValidator, message.PackageId, message.PackageNormalizedVersion); try { using (Stream snupkgstream = await _symbolFileService.DownloadSnupkgFileAsync(message.SnupkgUrl, token)) { try { using (Stream nupkgstream = await _symbolFileService.DownloadNupkgFileAsync(message.PackageId, message.PackageNormalizedVersion, token)) { var pdbs = _zipArchiveService.ReadFilesFromZipStream(snupkgstream, SymbolExtension); var pes = _zipArchiveService.ReadFilesFromZipStream(nupkgstream, PEExtensions); using (_telemetryService.TrackSymbolValidationDurationEvent(message.PackageId, message.PackageNormalizedVersion, pdbs.Count)) { if (!SymbolsHaveMatchingPEFiles(pdbs, pes)) { _telemetryService.TrackSymbolsValidationResultEvent(message.PackageId, message.PackageNormalizedVersion, ValidationStatus.Failed, nameof(ValidationIssue.SymbolErrorCode_MatchingPortablePDBNotFound)); return(ValidationResult.FailedWithIssues(ValidationIssue.SymbolErrorCode_MatchingPortablePDBNotFound)); } var targetDirectory = Settings.GetWorkingDirectory(); try { _logger.LogInformation("Extracting symbols to {TargetDirectory}", targetDirectory); var symbolFiles = _zipArchiveService.ExtractFilesFromZipStream(snupkgstream, targetDirectory, SymbolExtension); _logger.LogInformation("Extracting dlls to {TargetDirectory}", targetDirectory); _zipArchiveService.ExtractFilesFromZipStream(nupkgstream, targetDirectory, PEExtensions, symbolFiles); var status = ValidateSymbolMatching(targetDirectory, message.PackageId, message.PackageNormalizedVersion); return(status); } finally { TryCleanWorkingDirectoryForSeconds(targetDirectory, message.PackageId, message.PackageNormalizedVersion, _cleanWorkingDirectoryTimeSpan); } } } } catch (FileNotFoundException) { _telemetryService.TrackPackageNotFoundEvent(message.PackageId, message.PackageNormalizedVersion); return(ValidationResult.Failed); } } } catch (InvalidOperationException) { _telemetryService.TrackSymbolsPackageNotFoundEvent(message.PackageId, message.PackageNormalizedVersion); return(ValidationResult.Failed); } }
public async Task EnqueueSymbolsValidationMessageAsync(IValidationRequest request) { var message = new SymbolsValidatorMessage(validationId: request.ValidationId, symbolPackageKey: request.PackageKey, packageId: request.PackageId, packageNormalizedVersion: request.PackageVersion, snupkgUrl: request.NupkgUrl); var brokeredMessage = _serializer.Serialize(message); var visibleAt = DateTimeOffset.UtcNow + (_messageDelay ?? TimeSpan.Zero); brokeredMessage.ScheduledEnqueueTimeUtc = visibleAt; await _topicClient.SendAsync(brokeredMessage); }
public FactBase() { _symbolService = new Mock <ISymbolsValidatorService>(); _validatorStateService = new Mock <IValidatorStateService>(); _validationEnqueuer = new Mock <IPackageValidationEnqueuer>(); _featureFlagService = new Mock <IFeatureFlagService>(); _logger = new Mock <ILogger <SymbolsValidatorMessageHandler> >(); _featureFlagService.SetReturnsDefault(true); Target = new SymbolsValidatorMessageHandler( _symbolService.Object, _validatorStateService.Object, _validationEnqueuer.Object, _featureFlagService.Object, _logger.Object); _message = new SymbolsValidatorMessage(Guid.NewGuid(), 42, "TestPackage", "1.1.1", "url"); }
public async Task SendsSerializeMessage() { SymbolsValidatorMessage message = null; _serializer .Setup(x => x.Serialize(It.IsAny <SymbolsValidatorMessage>())) .Returns(() => _brokeredMessage.Object) .Callback <SymbolsValidatorMessage>(x => message = x); await _target.EnqueueSymbolsValidationMessageAsync(_validationRequest.Object); Assert.Equal(_validationRequest.Object.ValidationId, message.ValidationId); Assert.Equal(_validationRequest.Object.PackageId, message.PackageId); Assert.Equal(_validationRequest.Object.PackageVersion, message.PackageNormalizedVersion); Assert.Equal(_validationRequest.Object.NupkgUrl, message.SnupkgUrl); _serializer.Verify( x => x.Serialize(It.IsAny <SymbolsValidatorMessage>()), Times.Once); _topicClient.Verify(x => x.SendAsync(_brokeredMessage.Object), Times.Once); _topicClient.Verify(x => x.SendAsync(It.IsAny <IBrokeredMessage>()), Times.Once); }
public async Task <INuGetValidationResponse> ValidateSymbolsAsync(SymbolsValidatorMessage message, CancellationToken token) { _logger.LogInformation("{ValidatorName} :Start ValidateSymbolsAsync. PackageId: {packageId} PackageNormalizedVersion: {packageNormalizedVersion}", ValidatorName.SymbolsValidator, message.PackageId, message.PackageNormalizedVersion); try { using (Stream snupkgstream = await _symbolFileService.DownloadSnupkgFileAsync(message.SnupkgUrl, token)) { if (!await _zipArchiveService.ValidateZipAsync(snupkgstream, message.SnupkgUrl, token)) { return(NuGetValidationResponse.FailedWithIssues(ValidationIssue.SymbolErrorCode_SnupkgContainsEntriesNotSafeForExtraction)); } try { using (Stream nupkgstream = await _symbolFileService.DownloadNupkgFileAsync(message.PackageId, message.PackageNormalizedVersion, token)) { var pdbs = _zipArchiveService.ReadFilesFromZipStream(snupkgstream, SymbolExtension); var pes = _zipArchiveService.ReadFilesFromZipStream(nupkgstream, PEExtensions); if (pdbs.Count == 0) { return(NuGetValidationResponse.FailedWithIssues(ValidationIssue.SymbolErrorCode_SnupkgDoesNotContainSymbols)); } using (_telemetryService.TrackSymbolValidationDurationEvent(message.PackageId, message.PackageNormalizedVersion, pdbs.Count)) { List <string> orphanSymbolFiles; if (!SymbolsHaveMatchingPEFiles(pdbs, pes, out orphanSymbolFiles)) { orphanSymbolFiles.ForEach((symbol) => { _telemetryService.TrackSymbolsAssemblyValidationResultEvent(message.PackageId, message.PackageNormalizedVersion, ValidationStatus.Failed, nameof(ValidationIssue.SymbolErrorCode_MatchingAssemblyNotFound), assemblyName: symbol); }); _telemetryService.TrackSymbolsValidationResultEvent(message.PackageId, message.PackageNormalizedVersion, ValidationStatus.Failed); return(NuGetValidationResponse.FailedWithIssues(ValidationIssue.SymbolErrorCode_MatchingAssemblyNotFound)); } var targetDirectory = Settings.GetWorkingDirectory(); try { _logger.LogInformation("Extracting symbols to {TargetDirectory}", targetDirectory); var symbolFiles = _zipArchiveService.ExtractFilesFromZipStream(snupkgstream, targetDirectory, SymbolExtension); _logger.LogInformation("Extracting dlls to {TargetDirectory}", targetDirectory); _zipArchiveService.ExtractFilesFromZipStream(nupkgstream, targetDirectory, PEExtensions, symbolFiles); var status = ValidateSymbolMatching(targetDirectory, message.PackageId, message.PackageNormalizedVersion); return(status); } finally { TryCleanWorkingDirectoryForSeconds(targetDirectory, message.PackageId, message.PackageNormalizedVersion, _cleanWorkingDirectoryTimeSpan); } } } } catch (FileNotFoundException) { _telemetryService.TrackPackageNotFoundEvent(message.PackageId, message.PackageNormalizedVersion); return(NuGetValidationResponse.Failed); } } } catch (InvalidOperationException) { _telemetryService.TrackSymbolsPackageNotFoundEvent(message.PackageId, message.PackageNormalizedVersion); return(NuGetValidationResponse.Failed); } }