src/NuGetGallery/Services/SymbolPackageUploadService.cs
/// <summary>
/// This method does not perform the ownership validations for the symbols package. It is the responsibility
/// of the caller to do it. Also, this method does not dispose the <see cref="Stream"/> object, the caller 
/// should take care of it.
/// </summary>
/// <param name="symbolPackageStream"><see cref="Stream"/> object for the symbols package.</param>
/// <param name="currentUser">The user performing the uploads.</param>
/// <returns>Awaitable task for <see cref="SymbolPackageValidationResult"/></returns>
This method does not perform the ownership validations for the symbols package. It is the responsibility
of the caller to do it. Also, this method does not dispose the  object, the caller
should take care of it.
This method does not perform the ownership validations for the symbols package . It is the responsibility of the caller to do it . Also this method does not dispose the object the caller should take care of it .
public async Task<SymbolPackageValidationResult> ValidateUploadedSymbolsPackage(Stream symbolPackageStream, User currentUser)
        {
            Package package = null;
            if (!_contentObjectService.SymbolsConfiguration.IsSymbolsUploadEnabledForUser(currentUser))
            {
                return SymbolPackageValidationResult.UserNotAllowedToUpload(Strings.SymbolsPackage_UploadNotAllowed);
            }
            try
            {
                if (ZipArchiveHelpers.FoundEntryInFuture(symbolPackageStream, out ZipArchiveEntry entryInTheFuture))
                {
                    return SymbolPackageValidationResult.Invalid(string.Format(
                        CultureInfo.CurrentCulture,
                        Strings.PackageEntryFromTheFuture,
                        entryInTheFuture.Name));
                }
                using (var packageToPush = new PackageArchiveReader(symbolPackageStream, leaveStreamOpen: true))
                {
                    var nuspec = packageToPush.GetNuspecReader();
                    var id = nuspec.GetId();
                    var version = nuspec.GetVersion();
                    var normalizedVersion = version.ToNormalizedStringSafe();
                    package = _packageService.FindPackageByIdAndVersionStrict(id, version.ToStringSafe());
                    if (package == null || package.PackageStatusKey == PackageStatus.Deleted)
                    {
                        return SymbolPackageValidationResult.MissingPackage(string.Format(
                            CultureInfo.CurrentCulture,
                            Strings.SymbolsPackage_PackageIdAndVersionNotFound,
                            id,
                            normalizedVersion));
                    }
                    if (ValidationHelper.HasDuplicatedEntries(packageToPush))
                    {
                        return SymbolPackageValidationResult.Invalid(Strings.UploadPackage_PackageContainsDuplicatedEntries);
                    }
                    if (package.SymbolPackages.Any(sp => sp.StatusKey == PackageStatus.Validating))
                    {
                        return SymbolPackageValidationResult.SymbolsPackageExists(Strings.SymbolsPackage_ConflictValidating);
                    }
                    try
                    {
                        await _symbolPackageService.EnsureValidAsync(packageToPush);
                    }
                    catch (Exception ex)
                    {
                        ex.Log();
                        var message = Strings.SymbolsPackage_FailedToReadPackage;
                        if (ex is InvalidPackageException || ex is InvalidDataException || ex is EntityException)
                        {
                            message = ex.Message;
                        }
                        _telemetryService.TrackSymbolPackageFailedGalleryValidationEvent(id, normalizedVersion);
                        return SymbolPackageValidationResult.Invalid(message);
                    }
                }
                return SymbolPackageValidationResult.AcceptedForPackage(package);
            }
            catch (Exception ex) when (ex is InvalidPackageException
                || ex is InvalidDataException
                || ex is EntityException
                || ex is FrameworkException)
            {
                return SymbolPackageValidationResult.Invalid(
                    string.Format(CultureInfo.CurrentCulture, Strings.UploadPackage_InvalidPackage, ex.Message));
            }
        }
public async Task < SymbolPackageValidationResult > ValidateUploadedSymbolsPackage ( Stream symbolPackageStream , User currentUser ) { Package package = null ; if ( ! _contentObjectService . SymbolsConfiguration . IsSymbolsUploadEnabledForUser ( currentUser ) ) { return SymbolPackageValidationResult . UserNotAllowedToUpload ( Strings . SymbolsPackage_UploadNotAllowed ) ; } try { if ( ZipArchiveHelpers . FoundEntryInFuture ( symbolPackageStream , out ZipArchiveEntry entryInTheFuture ) ) { return SymbolPackageValidationResult . Invalid ( string . Format ( CultureInfo . CurrentCulture , Strings . PackageEntryFromTheFuture , entryInTheFuture . Name ) ) ; } using ( var packageToPush = new PackageArchiveReader ( symbolPackageStream , leaveStreamOpen : true ) ) { var nuspec = packageToPush . GetNuspecReader ( ) ; var id = nuspec . GetId ( ) ; var version = nuspec . GetVersion ( ) ; var normalizedVersion = version . ToNormalizedStringSafe ( ) ; package = _packageService . FindPackageByIdAndVersionStrict ( id , version . ToStringSafe ( ) ) ; if ( package == null || package . PackageStatusKey == PackageStatus . Deleted ) { return SymbolPackageValidationResult . MissingPackage ( string . Format ( CultureInfo . CurrentCulture , Strings . SymbolsPackage_PackageIdAndVersionNotFound , id , normalizedVersion ) ) ; } if ( ValidationHelper . HasDuplicatedEntries ( packageToPush ) ) { return SymbolPackageValidationResult . Invalid ( Strings . UploadPackage_PackageContainsDuplicatedEntries ) ; } if ( package . SymbolPackages . Any ( sp => sp . StatusKey == PackageStatus . Validating ) ) { return SymbolPackageValidationResult . SymbolsPackageExists ( Strings . SymbolsPackage_ConflictValidating ) ; } try { await _symbolPackageService . EnsureValidAsync ( packageToPush ) ; } catch ( Exception ex ) { ex . Log ( ) ; var message = Strings . SymbolsPackage_FailedToReadPackage ; if ( ex is InvalidPackageException || ex is InvalidDataException || ex is EntityException ) { message = ex . Message ; } _telemetryService . TrackSymbolPackageFailedGalleryValidationEvent ( id , normalizedVersion ) ; return SymbolPackageValidationResult . Invalid ( message ) ; } } return SymbolPackageValidationResult . AcceptedForPackage ( package ) ; } catch ( Exception ex ) when ( ex is InvalidPackageException || ex is InvalidDataException || ex is EntityException || ex is FrameworkException ) { return SymbolPackageValidationResult . Invalid ( string . Format ( CultureInfo . CurrentCulture , Strings . UploadPackage_InvalidPackage , ex . Message ) ) ; } }
This method does not perform the ownership validations for the symbols package.
This method does not perform the ownership validations for the symbols package .
// Check if symbol package upload is allowed for this user. // Ensure the corresponding package exists before pushing a snupkg. // Check for duplicated entries in symbols package // Do not allow to upload a snupkg to a package which has symbols package pending validations.
Awaitable task for
Awaitable task for
symbolPackageStream
Stream
object for the symbols package.
object for the symbols package .
currentUser
User
The user performing the uploads.
The user performing the uploads .