From 07ede7a14745c3b1adf4f22e704f1a5aa5529d75 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 11 Jul 2021 03:34:57 +0300 Subject: [PATCH 1/3] Disallow custom rulesets from score submission --- osu.Game/Screens/Play/SoloPlayer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/SoloPlayer.cs b/osu.Game/Screens/Play/SoloPlayer.cs index ef1087dd62..d90e8e0168 100644 --- a/osu.Game/Screens/Play/SoloPlayer.cs +++ b/osu.Game/Screens/Play/SoloPlayer.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using osu.Game.Online.API; using osu.Game.Online.Rooms; using osu.Game.Online.Solo; +using osu.Game.Rulesets; using osu.Game.Scoring; namespace osu.Game.Screens.Play @@ -27,7 +28,7 @@ namespace osu.Game.Screens.Play if (!(Beatmap.Value.BeatmapInfo.OnlineBeatmapID is int beatmapId)) return null; - if (!(Ruleset.Value.ID is int rulesetId)) + if (!(Ruleset.Value.ID is int rulesetId) || Ruleset.Value.ID > ILegacyRuleset.MAX_LEGACY_RULESET_ID) return null; return new CreateSoloScoreRequest(beatmapId, rulesetId, Game.VersionHash); From 6b8de2a10b6fc3cdbea511a66a4673c824c60fe8 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 11 Jul 2021 03:35:35 +0300 Subject: [PATCH 2/3] Add test coverage for excluded cases in score submission --- .../TestScenePlayerScoreSubmission.cs | 92 +++++++++++++++---- 1 file changed, 73 insertions(+), 19 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs index f9ccb10778..5ff2e9c439 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using NUnit.Framework; using osu.Framework.Screens; @@ -10,6 +11,7 @@ using osu.Game.Online.Rooms; using osu.Game.Online.Solo; using osu.Game.Rulesets; using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Ranking; @@ -17,17 +19,26 @@ using osu.Game.Tests.Beatmaps; namespace osu.Game.Tests.Visual.Gameplay { - public class TestScenePlayerScoreSubmission : OsuPlayerTestScene + public class TestScenePlayerScoreSubmission : PlayerTestScene { protected override bool AllowFail => allowFail; private bool allowFail; + private Func createCustomBeatmap; + private Func createCustomRuleset; + private DummyAPIAccess dummyAPI => (DummyAPIAccess)API; protected override bool HasCustomSteps => true; - protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) + protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false); + + protected override Ruleset CreatePlayerRuleset() => createCustomRuleset?.Invoke() ?? new OsuRuleset(); + + protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => createCustomBeatmap?.Invoke(ruleset) ?? createTestBeatmap(ruleset); + + private IBeatmap createTestBeatmap(RulesetInfo ruleset) { var beatmap = (TestBeatmap)base.CreateBeatmap(ruleset); @@ -36,14 +47,12 @@ namespace osu.Game.Tests.Visual.Gameplay return beatmap; } - protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false); - [Test] public void TestNoSubmissionOnResultsWithNoToken() { prepareTokenResponse(false); - CreateTest(() => allowFail = false); + createPlayerTest(); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -63,7 +72,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(true); - CreateTest(() => allowFail = false); + createPlayerTest(); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -82,7 +91,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(false); - CreateTest(() => allowFail = false); + createPlayerTest(); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -99,7 +108,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(true); - CreateTest(() => allowFail = true); + createPlayerTest(true); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -114,7 +123,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(true); - CreateTest(() => allowFail = true); + createPlayerTest(true); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -131,7 +140,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(true); - CreateTest(() => allowFail = false); + createPlayerTest(); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -144,7 +153,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(true); - CreateTest(() => allowFail = false); + createPlayerTest(); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -154,18 +163,49 @@ namespace osu.Game.Tests.Visual.Gameplay AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false); } - private void addFakeHit() + [Test] + public void TestNoSubmissionOnLocalBeatmap() { - AddUntilStep("wait for first result", () => Player.Results.Count > 0); + prepareTokenResponse(true); - AddStep("force successfuly hit", () => + createPlayerTest(false, r => { - Player.ScoreProcessor.RevertResult(Player.Results.First()); - Player.ScoreProcessor.ApplyResult(new OsuJudgementResult(Beatmap.Value.Beatmap.HitObjects.First(), new OsuJudgement()) - { - Type = HitResult.Great, - }); + var beatmap = createTestBeatmap(r); + beatmap.BeatmapInfo.OnlineBeatmapID = null; + return beatmap; }); + + AddUntilStep("wait for token request", () => Player.TokenCreationRequested); + + addFakeHit(); + + AddStep("exit", () => Player.Exit()); + AddAssert("ensure no submission", () => Player.SubmittedScore == null); + } + + [Test] + public void TestNoSubmissionOnCustomRuleset() + { + prepareTokenResponse(true); + + createPlayerTest(false, createRuleset: () => new OsuRuleset { RulesetInfo = { ID = 10 } }); + + AddUntilStep("wait for token request", () => Player.TokenCreationRequested); + + addFakeHit(); + + AddStep("exit", () => Player.Exit()); + AddAssert("ensure no submission", () => Player.SubmittedScore == null); + } + + private void createPlayerTest(bool allowFail = false, Func createBeatmap = null, Func createRuleset = null) + { + CreateTest(() => AddStep("set up requirements", () => + { + this.allowFail = allowFail; + createCustomBeatmap = createBeatmap; + createCustomRuleset = createRuleset; + })); } private void prepareTokenResponse(bool validToken) @@ -188,5 +228,19 @@ namespace osu.Game.Tests.Visual.Gameplay }; }); } + + private void addFakeHit() + { + AddUntilStep("wait for first result", () => Player.Results.Count > 0); + + AddStep("force successfuly hit", () => + { + Player.ScoreProcessor.RevertResult(Player.Results.First()); + Player.ScoreProcessor.ApplyResult(new OsuJudgementResult(Beatmap.Value.Beatmap.HitObjects.First(), new OsuJudgement()) + { + Type = HitResult.Great, + }); + }); + } } } From f21ea3b790812bf48d108601191b11e1b462f087 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sun, 11 Jul 2021 03:46:19 +0300 Subject: [PATCH 3/3] Update player test scene `Ruleset` bindable from creation method --- osu.Game/Tests/Visual/PlayerTestScene.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/Tests/Visual/PlayerTestScene.cs b/osu.Game/Tests/Visual/PlayerTestScene.cs index 088e997de9..93491c800f 100644 --- a/osu.Game/Tests/Visual/PlayerTestScene.cs +++ b/osu.Game/Tests/Visual/PlayerTestScene.cs @@ -57,7 +57,9 @@ namespace osu.Game.Tests.Visual protected void LoadPlayer() { - var ruleset = Ruleset.Value.CreateInstance(); + var ruleset = CreatePlayerRuleset(); + Ruleset.Value = ruleset.RulesetInfo; + var beatmap = CreateBeatmap(ruleset.RulesetInfo); Beatmap.Value = CreateWorkingBeatmap(beatmap);