mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 23:49:02 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RadicadeServer.Admin;
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.RecNet.Rooms;
|
||||
using Xunit;
|
||||
|
||||
namespace RadicadeServer.Tests;
|
||||
|
||||
[Collection(DbFactoryCollection.Name)]
|
||||
public class AdminBundleBindingTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task BindingRequiresAdminExistingBundleAndMatchingRoomAndPreservesRoomSave()
|
||||
{
|
||||
var root = Directory.CreateTempSubdirectory("radicade-bundle-binding-").FullName;
|
||||
var oldStorage = DBConfig.CDNStorage;
|
||||
var oldKey = DBConfig.AdminApiKey;
|
||||
DBConfig.CDNStorage = root;
|
||||
DBConfig.AdminApiKey = "binding-test-key";
|
||||
try
|
||||
{
|
||||
await using var db = new RecDBContext(TestDbOptions.Create()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
|
||||
var sub = new SubRoom { RoomId = 228, SubRoomId = 280, DataBlob = "original.room" };
|
||||
db.SubRooms.Add(sub);
|
||||
await db.SaveChangesAsync();
|
||||
var api = new AdminRoomAPI(db);
|
||||
var id = new string('a', 40);
|
||||
Assert.IsType<UnauthorizedObjectResult>(await api.BindAssetBundle("wrong", 228, 280, id));
|
||||
Assert.IsType<BadRequestObjectResult>(await api.BindAssetBundle("binding-test-key", 228, 280, "../bad"));
|
||||
Assert.IsType<BadRequestObjectResult>(await api.BindAssetBundle("binding-test-key", 228, 280, id));
|
||||
await File.WriteAllTextAsync(Path.Join(root, id + ".assetbundle"), "test bundle");
|
||||
Assert.IsType<NotFoundObjectResult>(await api.BindAssetBundle("binding-test-key", 229, 280, id));
|
||||
Assert.Equal("", sub.UnityAssetId);
|
||||
Assert.IsType<OkObjectResult>(await api.BindAssetBundle("binding-test-key", 228, 280, id));
|
||||
db.ChangeTracker.Clear();
|
||||
var stored = await db.SubRooms.SingleAsync();
|
||||
Assert.Equal(id, stored.UnityAssetId);
|
||||
Assert.Equal("original.room", stored.DataBlob);
|
||||
Assert.IsType<OkObjectResult>(await api.BindAssetBundle("binding-test-key", 228, 280, id));
|
||||
await File.WriteAllTextAsync(Path.Join(root, id), "shadowing manifest");
|
||||
Assert.IsType<BadRequestObjectResult>(await api.BindAssetBundle("binding-test-key", 228, 280, id));
|
||||
}
|
||||
finally
|
||||
{
|
||||
DBConfig.CDNStorage = oldStorage;
|
||||
DBConfig.AdminApiKey = oldKey;
|
||||
Directory.Delete(root, recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user