chore(deps): update jetbrains/qodana-action action to v2024 (#3195)
[ArchiSteamFarm.git] / ArchiSteamFarm.Tests / Utilities.cs
blob289d3114bc927ef0c6b299e8e177b767b2e604b2
1 // ----------------------------------------------------------------------------------------------
2 // _ _ _ ____ _ _____
3 // / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4 // / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5 // / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6 // /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7 // ----------------------------------------------------------------------------------------------
8 // |
9 // Copyright 2015-2024 Łukasz "JustArchi" Domeradzki
10 // Contact: JustArchi@JustArchi.net
11 // |
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
15 // |
16 // http://www.apache.org/licenses/LICENSE-2.0
17 // |
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
24 using System;
25 using System.Collections.Generic;
26 using Microsoft.VisualStudio.TestTools.UnitTesting;
27 using static ArchiSteamFarm.Core.Utilities;
29 namespace ArchiSteamFarm.Tests;
31 [TestClass]
32 #pragma warning disable CA1724 // We don't care about the potential conflict, as ASF class name has a priority
33 public sealed class Utilities {
34 [TestMethod]
35 public void AdditionallyForbiddenWordsWeakenPassphrases() => Assert.IsTrue(TestPasswordStrength("10chars<!>asdf", new HashSet<string> { "chars<!>" }).IsWeak);
37 [TestMethod]
38 public void ContextSpecificWordsWeakenPassphrases() => Assert.IsTrue(TestPasswordStrength("archisteamfarmpassword").IsWeak);
40 [TestMethod]
41 public void EasyPasswordsHaveMeaningfulReason() {
42 (bool isWeak, string? reason) = TestPasswordStrength("CorrectHorse");
44 Assert.IsTrue(isWeak);
45 Assert.IsTrue(reason?.Contains("Capitalization doesn't help very much", StringComparison.OrdinalIgnoreCase));
48 [TestMethod]
49 public void LongPassphraseIsNotWeak() => Assert.IsFalse(TestPasswordStrength("10chars<!>asdf").IsWeak);
51 [TestMethod]
52 public void MemePasswordIsNotWeak() => Assert.IsFalse(TestPasswordStrength("correcthorsebatterystaple").IsWeak);
54 [TestMethod]
55 public void RepeatedPasswordsHaveMeaningfulReason() {
56 (bool isWeak, string? reason) = TestPasswordStrength("abcabcabc");
58 Assert.IsTrue(isWeak);
59 Assert.IsTrue(reason?.Contains("Avoid repeated words and characters", StringComparison.OrdinalIgnoreCase));
62 [TestMethod]
63 public void RepetitiveCharactersWeakenPassphrases() => Assert.IsTrue(TestPasswordStrength("testaaaatest").IsWeak);
65 [TestMethod]
66 public void SequentialCharactersWeakenPassphrases() => Assert.IsTrue(TestPasswordStrength("testabcdtest").IsWeak);
68 [TestMethod]
69 public void SequentialDescendingCharactersWeakenPassphrases() => Assert.IsTrue(TestPasswordStrength("testdcbatest").IsWeak);
71 [TestMethod]
72 public void ShortPassphraseIsWeak() => Assert.IsTrue(TestPasswordStrength("four").IsWeak);
74 [TestMethod]
75 public void StraightRowsPasswordsHaveMeaningfulReason() {
76 (bool isWeak, string? reason) = TestPasswordStrength("`1234567890-=");
78 Assert.IsTrue(isWeak);
79 Assert.IsTrue(reason?.Contains("Straight rows of keys are easy to guess", StringComparison.OrdinalIgnoreCase));
82 #pragma warning restore CA1724 // We don't care about the potential conflict, as ASF class name has a priority