Initial commit - CDN

This commit is contained in:
2026-08-05 21:15:12 +03:00
commit 689475cde8
546 changed files with 10579 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../CDN/CDN.csproj" />
</ItemGroup>
</Project>
+126
View File
@@ -0,0 +1,126 @@
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Xunit;
using System.Net.Http.Json;
namespace CDN.Tests;
public class FileUploadTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
public FileUploadTests(WebApplicationFactory<Program> factory)
{
_factory = factory;
}
private string GenerateToken()
{
var key = Encoding.UTF8.GetBytes("this_is_a_very_secret_key_for_development_purposes");
var securityKey = new SymmetricSecurityKey(key);
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var claims = new[]
{
new Claim(JwtRegisteredClaimNames.Sub, "testuser"),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
};
var token = new JwtSecurityToken(
issuer: "MassTechCDN",
audience: "MassTechClients",
claims: claims,
expires: DateTime.Now.AddMinutes(30),
signingCredentials: credentials);
return new JwtSecurityTokenHandler().WriteToken(token);
}
[Fact]
public async Task Upload_Image_ReturnsSuccessAndUrl()
{
// Arrange
var client = _factory.CreateClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GenerateToken());
var content = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(new byte[] {
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, // Magic
0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, // IHDR
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, // Width 1, Height 1
0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, // Bit depth, Color type
0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, 0x41, // IDAT chunk length
0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, // IDAT data
0x05, 0x00, 0x01, 0x0D, 0x0A, 0x2D, 0xB4, 0x00,
0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, // IEND
0x42, 0x60, 0x82
});
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/png");
content.Add(fileContent, "file", "test.png");
// Act
var response = await client.PostAsync("/api/files/upload?w=100&h=100", content);
// Assert
response.EnsureSuccessStatusCode();
var responseString = await response.Content.ReadAsStringAsync();
Assert.Contains("File uploaded successfully", responseString);
}
[Fact]
public async Task Upload_NoFile_ReturnsBadRequest()
{
// Arrange
var client = _factory.CreateClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GenerateToken());
var content = new MultipartFormDataContent(); // Empty
// Act
var response = await client.PostAsync("/api/files/upload", content);
// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
[Fact]
public async Task Delete_File_ReturnsSuccess()
{
// Arrange
var client = _factory.CreateClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GenerateToken());
// First upload a file to get a known filename
var content = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(new byte[] {
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, // Magic
0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, // IHDR
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, // Width 1, Height 1
0x08, 0x06, 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, // Bit depth, Color type
0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, 0x41, // IDAT chunk length
0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, // IDAT data
0x05, 0x00, 0x01, 0x0D, 0x0A, 0x2D, 0xB4, 0x00,
0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, // IEND
0x42, 0x60, 0x82
});
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/png");
content.Add(fileContent, "file", "todelete.png");
var uploadRes = await client.PostAsync("/api/files/upload", content);
uploadRes.EnsureSuccessStatusCode();
var json = await uploadRes.Content.ReadFromJsonAsync<UploadResponse>();
var fileName = json.FileName; // This will likely be [guid].webp
// Act
var deleteRes = await client.DeleteAsync($"/api/files/{fileName}");
// Assert
deleteRes.EnsureSuccessStatusCode();
}
private class UploadResponse { public string FileName { get; set; } }
}
BIN
View File
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "9.0.0"
}
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
+219
View File
@@ -0,0 +1,219 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"CDN/1.0.0": {
"dependencies": {
"Microsoft.AspNetCore.Authentication.JwtBearer": "9.0.0",
"Microsoft.AspNetCore.OpenApi": "9.0.10",
"SixLabors.ImageSharp": "3.1.12"
},
"runtime": {
"CDN.dll": {}
}
},
"Microsoft.AspNetCore.Authentication.JwtBearer/9.0.0": {
"dependencies": {
"Microsoft.IdentityModel.Protocols.OpenIdConnect": "8.0.1"
},
"runtime": {
"lib/net9.0/Microsoft.AspNetCore.Authentication.JwtBearer.dll": {
"assemblyVersion": "9.0.0.0",
"fileVersion": "9.0.24.52903"
}
}
},
"Microsoft.AspNetCore.OpenApi/9.0.10": {
"dependencies": {
"Microsoft.OpenApi": "1.6.17"
},
"runtime": {
"lib/net9.0/Microsoft.AspNetCore.OpenApi.dll": {
"assemblyVersion": "9.0.10.0",
"fileVersion": "9.0.1025.47517"
}
}
},
"Microsoft.IdentityModel.Abstractions/8.0.1": {
"runtime": {
"lib/net9.0/Microsoft.IdentityModel.Abstractions.dll": {
"assemblyVersion": "8.0.1.0",
"fileVersion": "8.0.1.50722"
}
}
},
"Microsoft.IdentityModel.JsonWebTokens/8.0.1": {
"dependencies": {
"Microsoft.IdentityModel.Tokens": "8.0.1"
},
"runtime": {
"lib/net9.0/Microsoft.IdentityModel.JsonWebTokens.dll": {
"assemblyVersion": "8.0.1.0",
"fileVersion": "8.0.1.50722"
}
}
},
"Microsoft.IdentityModel.Logging/8.0.1": {
"dependencies": {
"Microsoft.IdentityModel.Abstractions": "8.0.1"
},
"runtime": {
"lib/net9.0/Microsoft.IdentityModel.Logging.dll": {
"assemblyVersion": "8.0.1.0",
"fileVersion": "8.0.1.50722"
}
}
},
"Microsoft.IdentityModel.Protocols/8.0.1": {
"dependencies": {
"Microsoft.IdentityModel.Tokens": "8.0.1"
},
"runtime": {
"lib/net9.0/Microsoft.IdentityModel.Protocols.dll": {
"assemblyVersion": "8.0.1.0",
"fileVersion": "8.0.1.50722"
}
}
},
"Microsoft.IdentityModel.Protocols.OpenIdConnect/8.0.1": {
"dependencies": {
"Microsoft.IdentityModel.Protocols": "8.0.1",
"System.IdentityModel.Tokens.Jwt": "8.0.1"
},
"runtime": {
"lib/net9.0/Microsoft.IdentityModel.Protocols.OpenIdConnect.dll": {
"assemblyVersion": "8.0.1.0",
"fileVersion": "8.0.1.50722"
}
}
},
"Microsoft.IdentityModel.Tokens/8.0.1": {
"dependencies": {
"Microsoft.IdentityModel.Logging": "8.0.1"
},
"runtime": {
"lib/net9.0/Microsoft.IdentityModel.Tokens.dll": {
"assemblyVersion": "8.0.1.0",
"fileVersion": "8.0.1.50722"
}
}
},
"Microsoft.OpenApi/1.6.17": {
"runtime": {
"lib/netstandard2.0/Microsoft.OpenApi.dll": {
"assemblyVersion": "1.6.17.0",
"fileVersion": "1.6.17.0"
}
}
},
"SixLabors.ImageSharp/3.1.12": {
"runtime": {
"lib/net6.0/SixLabors.ImageSharp.dll": {
"assemblyVersion": "3.0.0.0",
"fileVersion": "3.1.12.0"
}
}
},
"System.IdentityModel.Tokens.Jwt/8.0.1": {
"dependencies": {
"Microsoft.IdentityModel.JsonWebTokens": "8.0.1",
"Microsoft.IdentityModel.Tokens": "8.0.1"
},
"runtime": {
"lib/net9.0/System.IdentityModel.Tokens.Jwt.dll": {
"assemblyVersion": "8.0.1.0",
"fileVersion": "8.0.1.50722"
}
}
}
}
},
"libraries": {
"CDN/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.AspNetCore.Authentication.JwtBearer/9.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-bs+1Pq3vQdS2lTyxNUd9fEhtMsq3eLUpK36k2t56iDMVrk6OrAoFtvrQrTK0Y0OetTcJrUkGU7hBlf+ORzHLqQ==",
"path": "microsoft.aspnetcore.authentication.jwtbearer/9.0.0",
"hashPath": "microsoft.aspnetcore.authentication.jwtbearer.9.0.0.nupkg.sha512"
},
"Microsoft.AspNetCore.OpenApi/9.0.10": {
"type": "package",
"serviceable": true,
"sha512": "sha512-yAv5EDEi0Nkk75Vhxh6ppuXd/QIO8hzjGpAt/fGInMZWIX/mVwZ1IM50YFIWeLCVM8KDj0oFPQdcLeQ+9hEJsw==",
"path": "microsoft.aspnetcore.openapi/9.0.10",
"hashPath": "microsoft.aspnetcore.openapi.9.0.10.nupkg.sha512"
},
"Microsoft.IdentityModel.Abstractions/8.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-OtlIWcyX01olfdevPKZdIPfBEvbcioDyBiE/Z2lHsopsMD7twcKtlN9kMevHmI5IIPhFpfwCIiR6qHQz1WHUIw==",
"path": "microsoft.identitymodel.abstractions/8.0.1",
"hashPath": "microsoft.identitymodel.abstractions.8.0.1.nupkg.sha512"
},
"Microsoft.IdentityModel.JsonWebTokens/8.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-s6++gF9x0rQApQzOBbSyp4jUaAlwm+DroKfL8gdOHxs83k8SJfUXhuc46rDB3rNXBQ1MVRxqKUrqFhO/M0E97g==",
"path": "microsoft.identitymodel.jsonwebtokens/8.0.1",
"hashPath": "microsoft.identitymodel.jsonwebtokens.8.0.1.nupkg.sha512"
},
"Microsoft.IdentityModel.Logging/8.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-UCPF2exZqBXe7v/6sGNiM6zCQOUXXQ9+v5VTb9gPB8ZSUPnX53BxlN78v2jsbIvK9Dq4GovQxo23x8JgWvm/Qg==",
"path": "microsoft.identitymodel.logging/8.0.1",
"hashPath": "microsoft.identitymodel.logging.8.0.1.nupkg.sha512"
},
"Microsoft.IdentityModel.Protocols/8.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-uA2vpKqU3I2mBBEaeJAWPTjT9v1TZrGWKdgK6G5qJd03CLx83kdiqO9cmiK8/n1erkHzFBwU/RphP83aAe3i3g==",
"path": "microsoft.identitymodel.protocols/8.0.1",
"hashPath": "microsoft.identitymodel.protocols.8.0.1.nupkg.sha512"
},
"Microsoft.IdentityModel.Protocols.OpenIdConnect/8.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-AQDbfpL+yzuuGhO/mQhKNsp44pm5Jv8/BI4KiFXR7beVGZoSH35zMV3PrmcfvSTsyI6qrcR898NzUauD6SRigg==",
"path": "microsoft.identitymodel.protocols.openidconnect/8.0.1",
"hashPath": "microsoft.identitymodel.protocols.openidconnect.8.0.1.nupkg.sha512"
},
"Microsoft.IdentityModel.Tokens/8.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-kDimB6Dkd3nkW2oZPDkMkVHfQt3IDqO5gL0oa8WVy3OP4uE8Ij+8TXnqg9TOd9ufjsY3IDiGz7pCUbnfL18tjg==",
"path": "microsoft.identitymodel.tokens/8.0.1",
"hashPath": "microsoft.identitymodel.tokens.8.0.1.nupkg.sha512"
},
"Microsoft.OpenApi/1.6.17": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Le+kehlmrlQfuDFUt1zZ2dVwrhFQtKREdKBo+rexOwaCoYP0/qpgT9tLxCsZjsgR5Itk1UKPcbgO+FyaNid/bA==",
"path": "microsoft.openapi/1.6.17",
"hashPath": "microsoft.openapi.1.6.17.nupkg.sha512"
},
"SixLabors.ImageSharp/3.1.12": {
"type": "package",
"serviceable": true,
"sha512": "sha512-iAg6zifihXEFS/t7fiHhZBGAdCp3FavsF4i2ZIDp0JfeYeDVzvmlbY1CNhhIKimaIzrzSi5M/NBFcWvZT2rB/A==",
"path": "sixlabors.imagesharp/3.1.12",
"hashPath": "sixlabors.imagesharp.3.1.12.nupkg.sha512"
},
"System.IdentityModel.Tokens.Jwt/8.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-GJw3bYkWpOgvN3tJo5X4lYUeIFA2HD293FPUhKmp7qxS+g5ywAb34Dnd3cDAFLkcMohy5XTpoaZ4uAHuw0uSPQ==",
"path": "system.identitymodel.tokens.jwt/8.0.1",
"hashPath": "system.identitymodel.tokens.jwt.8.0.1.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,19 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "9.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
@@ -0,0 +1 @@
{"Version":1,"ManifestType":"Build","Endpoints":[]}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
{
"CDN, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": "\/mnt\/Dataa\/Work\/Programming\/MainProgram\/Backend\/APIs\/CDN\/CDN"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"JWT": {
"Key": "this_is_a_very_secret_key_for_development_purposes",
"Issuer": "MassTechCDN",
"Audience": "MassTechClients"
}
}
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More