Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Commit

Permalink
(GH-14) Adding IconUrl check
Browse files Browse the repository at this point in the history
- To ensure that the IconUrl either comes from the same domain as the
ProjectUrl, or comes from the RawGit CDN
- Fixes GH-14
  • Loading branch information
gep13 committed Nov 29, 2015
1 parent 2afe771 commit ce02888
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<Compile Include="infrastructure.app\rules\CopyrightWordCountMinimum4Requirement.cs" />
<Compile Include="infrastructure.app\rules\DocsUrlMissingSuggestion.cs" />
<Compile Include="infrastructure.app\rules\IconUrlMissingGuideline.cs" />
<Compile Include="infrastructure.app\rules\IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline.cs" />
<Compile Include="infrastructure.app\rules\InstallAutomationScriptNamedCorrectlyRequirement.cs" />
<Compile Include="infrastructure.app\rules\LicenseUrlDoesNotMatchProjectUrlGuideline.cs" />
<Compile Include="infrastructure.app\rules\LicenseUrlMissingGuideline.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright © 2015 - Present RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.package.validator.infrastructure.app.rules
{
using NuGet;
using infrastructure.rules;

public class IconUrlNotSameDomainAsProjectUrlDomainOrRawGitGuideline : BasePackageRule
{
public override string ValidationFailureMessage { get { return "The package IconUrl should ideally come from the same domain name as the Project Url, or hosted on the RawGit CDN. **NOTE:** For further information on how to setup your icon with a RawGit CDN URL, please visit this [article](https://github.com/chocolatey/choco/wiki/CreatePackages#package-icon-guidelines)."; } }

protected override PackageValidationOutput is_valid(IPackage package)
{
if(package.IconUrl == null) return true;

var iconUrlHost = package.IconUrl.Host;

// Since there is an iconUrl, but no Project Url, the check has to return false
// since the domains are definitely not the same
if(package.ProjectUrl == null) return false;

var projectUrlHost = package.ProjectUrl.Host;

return iconUrlHost == projectUrlHost || iconUrlHost == "cdn.rawgit.com";
}
}
}

0 comments on commit ce02888

Please sign in to comment.