Skip to content

Commit

Permalink
Regression test for #2064
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Jan 3, 2025
1 parent 4a89ff5 commit 4605afe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task RunTests(
await using var engineTest = new EngineTest(instanceClient.Engine, instanceClient.Jobs, fileDownloader, instanceClient.Metadata, testVersion.Engine.Value);
await using var chatTest = new ChatTest(instanceClient.ChatBots, instanceManagerClient, instanceClient.Jobs, instanceClient.Metadata);
var configTest = new ConfigurationTest(instanceClient.Configuration, instanceClient.Metadata);
await using var repoTest = new RepositoryTest(instanceClient.Repository, instanceClient.Jobs);
await using var repoTest = new RepositoryTest(instanceClient, instanceClient.Repository, instanceClient.Jobs);
await using var dmTest = new DeploymentTest(instanceClient, instanceClient.Jobs, dmPort, ddPort, lowPrioDeployment, testVersion);

var byondTask = engineTest.Run(cancellationToken, out var firstInstall);
Expand Down
28 changes: 27 additions & 1 deletion tests/Tgstation.Server.Tests/Live/Instance/RepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Request;
using Tgstation.Server.Api.Models.Response;
using Tgstation.Server.Api.Rights;
using Tgstation.Server.Client;
using Tgstation.Server.Client.Components;

namespace Tgstation.Server.Tests.Live.Instance
{
sealed class RepositoryTest : JobsRequiredTest
{
readonly IInstanceClient instanceClient;
readonly IRepositoryClient repositoryClient;

public RepositoryTest(IRepositoryClient repositoryClient, IJobsClient jobsClient)
public RepositoryTest(IInstanceClient instanceClient, IRepositoryClient repositoryClient, IJobsClient jobsClient)
: base(jobsClient)
{
this.instanceClient = instanceClient ?? throw new ArgumentNullException(nameof(instanceClient));
this.repositoryClient = repositoryClient ?? throw new ArgumentNullException(nameof(repositoryClient));
}

Expand Down Expand Up @@ -141,6 +144,29 @@ await repositoryClient.Update(new RepositoryUpdateRequest

var prNumber = 2;
await TestMergeTests(updated, prNumber, cancellationToken);

await RegressionTest2064(cancellationToken);
}

async ValueTask RegressionTest2064(CancellationToken cancellationToken)
{
var oldPerms = await instanceClient.PermissionSets.Read(cancellationToken);

var newPerms = await instanceClient.PermissionSets.Update(new InstancePermissionSetRequest
{
PermissionSetId = oldPerms.PermissionSetId,
RepositoryRights = RepositoryRights.SetSha,
}, cancellationToken);

Assert.AreEqual(RepositoryRights.SetSha, newPerms.RepositoryRights);

await ApiAssert.ThrowsException<InsufficientPermissionsException>(async () => await repositoryClient.Read(cancellationToken));

await instanceClient.PermissionSets.Update(new InstancePermissionSetRequest
{
PermissionSetId = oldPerms.PermissionSetId,
RepositoryRights = oldPerms.RepositoryRights,
}, cancellationToken);
}

async ValueTask RecloneTest(CancellationToken cancellationToken)
Expand Down
4 changes: 2 additions & 2 deletions tests/Tgstation.Server.Tests/Live/TestLiveServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -1942,7 +1942,7 @@ await adminClient.Execute(
Assert.AreEqual(expectedStaged, currentDD.ActiveCompileJob.Job.Id.Value);
Assert.IsNull(currentDD.StagedCompileJob);

await using var repoTestObj = new RepositoryTest(instanceClient.Repository, instanceClient.Jobs);
await using var repoTestObj = new RepositoryTest(instanceClient, instanceClient.Repository, instanceClient.Jobs);
var repoTest = repoTestObj.RunPostTest(cancellationToken);
await using var chatTestObj = new ChatTest(instanceClient.ChatBots, restAdminClient.Instances, instanceClient.Jobs, instance);
await chatTestObj.RunPostTest(cancellationToken);
Expand Down

0 comments on commit 4605afe

Please sign in to comment.