Skip to content

Commit 853651b

Browse files
authored
Merge pull request #6 from ghost1face/expand-support
Expand support
2 parents de23b8e + 725d361 commit 853651b

30 files changed

+603
-150
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @ghost1face

.github/workflows/dotnet.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: .NET
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Setup .NET
17+
uses: actions/setup-dotnet@v1
18+
with:
19+
dotnet-version: '6.0.x'
20+
- name: Restore dependencies
21+
working-directory: ./src
22+
run: dotnet restore
23+
- name: Build
24+
working-directory: ./src
25+
run: dotnet build --no-restore --configuration Release
26+
- name: Test
27+
working-directory: ./src
28+
run: dotnet test --no-build --verbosity normal --configuration Release

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
netstandard library for detecting file types by 'magic numbers', similar to the `file` command in Linux/Unix. Useful for validating file uploads instead of trusting file extensions.
44

5+
[![.NET](https://github.com/ghost1face/FileTypeInterrogator/actions/workflows/dotnet.yml/badge.svg?branch=master)](https://github.com/ghost1face/FileTypeInterrogator/actions/workflows/dotnet.yml)
56
[![NuGet](https://img.shields.io/nuget/v/FileTypeInterrogator.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/FileTypeInterrogator/)
67

78
# Usage
Lines changed: 25 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,28 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
4-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5-
<PropertyGroup>
6-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8-
<ProjectGuid>{8181D724-8886-4541-8819-9FF208A28074}</ProjectGuid>
9-
<OutputType>Library</OutputType>
10-
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>FileTypeInterrogator.Tests</RootNamespace>
12-
<AssemblyName>FileTypeInterrogator.Tests</AssemblyName>
13-
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
14-
<FileAlignment>512</FileAlignment>
15-
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
16-
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
17-
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
18-
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
19-
<IsCodedUITest>False</IsCodedUITest>
20-
<TestProjectType>UnitTest</TestProjectType>
21-
<NuGetPackageImportStamp>
22-
</NuGetPackageImportStamp>
23-
<TargetFrameworkProfile />
24-
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
25-
</PropertyGroup>
26-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
27-
<DebugSymbols>true</DebugSymbols>
28-
<DebugType>full</DebugType>
29-
<Optimize>false</Optimize>
30-
<OutputPath>bin\Debug\</OutputPath>
31-
<DefineConstants>DEBUG;TRACE</DefineConstants>
32-
<ErrorReport>prompt</ErrorReport>
33-
<WarningLevel>4</WarningLevel>
34-
</PropertyGroup>
35-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
36-
<DebugType>pdbonly</DebugType>
37-
<Optimize>true</Optimize>
38-
<OutputPath>bin\Release\</OutputPath>
39-
<DefineConstants>TRACE</DefineConstants>
40-
<ErrorReport>prompt</ErrorReport>
41-
<WarningLevel>4</WarningLevel>
42-
</PropertyGroup>
43-
<ItemGroup>
44-
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
45-
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
46-
</Reference>
47-
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
48-
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
49-
</Reference>
50-
<Reference Include="System" />
51-
<Reference Include="System.Core" />
52-
</ItemGroup>
53-
<ItemGroup>
54-
<Compile Include="FileTypeInterrogatorTests.cs" />
55-
<Compile Include="FileTypeInterrogatorTests_Alias.cs" />
56-
<Compile Include="Properties\AssemblyInfo.cs" />
57-
</ItemGroup>
58-
<ItemGroup>
59-
<None Include="packages.config" />
60-
<None Include="TestFiles\*">
61-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
62-
</None>
63-
</ItemGroup>
64-
<ItemGroup>
65-
<ProjectReference Include="..\FileTypeInterrogator\FileTypeInterrogator.csproj">
66-
<Project>{e5333901-a30a-45d0-b787-bc2f58208f9f}</Project>
67-
<Name>FileTypeInterrogator</Name>
68-
</ProjectReference>
69-
</ItemGroup>
70-
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
71-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
72-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
733
<PropertyGroup>
74-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
4+
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
5+
<IsPackable>false</IsPackable>
756
</PropertyGroup>
76-
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
77-
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
78-
</Target>
79-
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
7+
8+
<ItemGroup>
9+
<PackageReference Include="coverlet.collector" Version="1.2.0">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
</PackageReference>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
15+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\FileTypeInterrogator\FileTypeInterrogator.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<None Update="TestFiles\*.*">
24+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
</None>
26+
</ItemGroup>
27+
8028
</Project>

src/FileTypeInterrogator.Tests/FileTypeInterrogatorTests.cs

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,89 +44,109 @@ public void CanDetectUTF8BOM()
4444
}
4545

4646
[DataTestMethod]
47-
[DataRow("PDF", DisplayName = "PDF Test")]
48-
[DataRow("FDF", DisplayName = "FDF Test")]
47+
[DataRow("pdf", DisplayName = "PDF Test")]
48+
[DataRow("fdf", DisplayName = "FDF Test")]
4949
public void CanDetectAdobe(string extension)
5050
{
5151
DetectType(extension);
5252
}
5353

5454
[DataTestMethod]
55-
[DataRow("BMP", DisplayName = "BMP Test")]
56-
[DataRow("GIF", DisplayName = "GIF Test")]
57-
[DataRow("ICO", DisplayName = "ICO Test")]
58-
[DataRow("JP2", DisplayName = "JP2 Test")]
59-
[DataRow("JPG", DisplayName = "JPG Test")]
60-
[DataRow("PNG", DisplayName = "PNG Test")]
61-
[DataRow("PSD", DisplayName = "PSD Test")]
62-
[DataRow("TIF", DisplayName = "TIF Test")]
55+
[DataRow("ai", DisplayName = "AI Test")]
56+
[DataRow("bmp", DisplayName = "BMP Test")]
57+
[DataRow("gif", DisplayName = "GIF Test")]
58+
[DataRow("ico", DisplayName = "ICO Test")]
59+
[DataRow("jp2", DisplayName = "JP2 Test")]
60+
[DataRow("jpg", DisplayName = "JPG Test")]
61+
[DataRow("pcx", DisplayName = "PCX Test")]
62+
[DataRow("png", DisplayName = "PNG Test")]
63+
[DataRow("psd", DisplayName = "PSD Test")]
64+
[DataRow("tif", DisplayName = "TIF Test")]
65+
[DataRow("webp", DisplayName = "WEBP Test")]
6366
public void CanDetectImages(string extension)
6467
{
6568
DetectType(extension);
6669
}
6770

6871
[DataTestMethod]
69-
[DataRow("3GP", DisplayName = "3GP Test")]
70-
[DataRow("AVI", DisplayName = "AVI Test")]
71-
[DataRow("FLV", DisplayName = "FLV Test")]
72-
[DataRow("MID", DisplayName = "MID Test")]
73-
[DataRow("MP4", DisplayName = "MP4 Test")]
74-
[DataRow("WMV", DisplayName = "WMV Test")]
72+
[DataRow("3gp", DisplayName = "3GP Test")]
73+
[DataRow("avi", DisplayName = "AVI Test")]
74+
[DataRow("flv", DisplayName = "FLV Test")]
75+
[DataRow("mid", DisplayName = "MID Test")]
76+
[DataRow("mkv", DisplayName = "MKV Test")]
77+
[DataRow("mp4", DisplayName = "MP4 Test")]
78+
[DataRow("webm", DisplayName = "WEBM Test")]
79+
[DataRow("wmv", DisplayName = "WMV Test")]
7580
public void CanDetectVideo(string extension)
7681
{
7782
DetectType(extension);
7883
}
7984

8085
[DataTestMethod]
81-
[DataRow("AC3", DisplayName = "AC3 Test")]
82-
[DataRow("AIFF", DisplayName = "AIFF Test")]
83-
[DataRow("FLAC", DisplayName = "FLAC Test")]
84-
[DataRow("MP3", DisplayName = "MP3 Test")]
85-
[DataRow("OGG", DisplayName = "OGG Test")]
86-
[DataRow("RA", DisplayName = "RA Test")]
86+
[DataRow("ac3", DisplayName = "AC3 Test")]
87+
[DataRow("aiff", DisplayName = "AIFF Test")]
88+
[DataRow("flac", DisplayName = "FLAC Test")]
89+
[DataRow("mp3", DisplayName = "MP3 Test")]
90+
[DataRow("ogg", DisplayName = "OGG Test")]
91+
[DataRow("ra", DisplayName = "RA Test")]
92+
[DataRow("wav", DisplayName = "WAV Test")]
8793
public void CanDetectAudio(string extension)
8894
{
8995
DetectType(extension);
9096
}
9197

9298
[DataTestMethod]
93-
[DataRow("DOC", DisplayName = "DOC Test")]
94-
[DataRow("DOCX", DisplayName = "DOC Test")]
95-
[DataRow("PPT", DisplayName = "PPT Test")]
96-
[DataRow("PPTX", DisplayName = "PPTX Test")]
97-
[DataRow("XLS", DisplayName = "XLS Test")]
98-
[DataRow("XLSX", DisplayName = "XLSX Test")]
99+
[DataRow("doc", DisplayName = "DOC Test")]
100+
[DataRow("docx", DisplayName = "DOC Test")]
101+
[DataRow("odp", DisplayName = "ODP Test")]
102+
[DataRow("odt", DisplayName = "ODT Test")]
103+
[DataRow("ppt", DisplayName = "PPT Test")]
104+
[DataRow("pptx", DisplayName = "PPTX Test")]
105+
[DataRow("rtf", DisplayName = "RTF Test")]
106+
[DataRow("xls", DisplayName = "XLS Test")]
107+
[DataRow("xlsx", DisplayName = "XLSX Test")]
99108
public void CanDetectOffice(string extension)
100109
{
101110
DetectType(extension);
102111
}
103112

104113
[DataTestMethod]
105-
[DataRow("OTF", DisplayName = "OTF Test")]
106-
[DataRow("TTF", DisplayName = "TTF Test")]
107-
[DataRow("WOFF", DisplayName = "WOFF Test")]
114+
[DataRow("otf", DisplayName = "OTF Test")]
115+
[DataRow("ttf", DisplayName = "TTF Test")]
116+
[DataRow("woff", DisplayName = "WOFF Test")]
108117
public void CanDetectFont(string extension)
109118
{
110119
DetectType(extension);
111120
}
112121

113122
[DataTestMethod]
114-
[DataRow("7Z", DisplayName = "7Z Test")]
115-
[DataRow("RAR", DisplayName = "RAR Test")]
116-
[DataRow("ZIP", DisplayName = "ZIP Test")]
123+
[DataRow("7z", DisplayName = "7Z Test")]
124+
[DataRow("gz", DisplayName = "GZ Test")]
125+
[DataRow("rar", DisplayName = "RAR Test")]
126+
[DataRow("zip", DisplayName = "ZIP Test")]
117127
public void CanDetectCompressed(string extension)
118128
{
119129
DetectType(extension);
120130
}
121131

132+
[DataTestMethod]
133+
[DataRow("eml", DisplayName = "EML Test")]
134+
[DataRow("vcf", DisplayName = "VCF Test")]
135+
public void CanDetectOther(string extension)
136+
{
137+
DetectType(extension);
138+
}
139+
122140
private void DetectType(string extension)
123141
{
124142
DetectType(extension, result =>
125143
{
126144
Assert.IsNotNull(result);
127145
Assert.IsTrue(
128146
result.FileType.Equals(extension, StringComparison.OrdinalIgnoreCase) ||
129-
result.Alias?.Any(a => a.Equals(extension, StringComparison.OrdinalIgnoreCase)) == true);
147+
result.Alias?.Any(a => a.Equals(extension, StringComparison.OrdinalIgnoreCase)) == true,
148+
"{0} and/or {1} do not equal {2}",
149+
result.FileType, result.Alias?.FirstOrDefault(), extension);
130150
});
131151
}
132152

src/FileTypeInterrogator.Tests/FileTypeInterrogatorTests_Alias.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Init()
1717
[TestMethod]
1818
public void CanDetectAlias_Jpg()
1919
{
20-
var filePath = GetFileByType("JPG");
20+
var filePath = GetFileByType("jpg");
2121
var fileContents = File.ReadAllBytes(filePath);
2222

2323
var result = fileTypeInterrogator.IsType(fileContents, "jpg");
@@ -28,7 +28,7 @@ public void CanDetectAlias_Jpg()
2828
[TestMethod]
2929
public void CanDetectAlias_Jpeg()
3030
{
31-
var filePath = GetFileByType("JPG");
31+
var filePath = GetFileByType("jpg");
3232
var fileContents = File.ReadAllBytes(filePath);
3333

3434
var result = fileTypeInterrogator.IsType(fileContents, "jpeg");
@@ -39,7 +39,7 @@ public void CanDetectAlias_Jpeg()
3939
[TestMethod]
4040
public void CanDetectJpg_By_MimeType()
4141
{
42-
var filePath = GetFileByType("JPG");
42+
var filePath = GetFileByType("jpg");
4343
var fileContents = File.ReadAllBytes(filePath);
4444

4545
var result = fileTypeInterrogator.IsType(fileContents, "image/jpeg");

src/FileTypeInterrogator.Tests/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
6 KB
Binary file not shown.
9 KB
Binary file not shown.
6 KB
Binary file not shown.

0 commit comments

Comments
 (0)