Skip to content

Commit eff3003

Browse files
salvatore-piccionedependabot[bot]Salvatore Piccione
authored
feat: improve tampering test on exercise "Authentication System" (#2193)
* build(deps): bump actions/checkout from 4.1.0 to 4.1.1 (#2192) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@8ade135...b4ffde6) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: improve tampering test on exercise "Authentication System" * feat: improve test readability --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Salvatore Piccione <Salvatore.Piccione@wolterskluwer.com>
1 parent 788c6ee commit eff3003

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

exercises/concept/authentication-system/.meta/Exemplar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Identity Admin
4040
get { return new Identity { Email = admin.Email, EyeColor = admin.EyeColor }; }
4141
}
4242

43-
public IReadOnlyDictionary<string, Identity> GetDevelopers()
43+
public IDictionary<string, Identity> GetDevelopers()
4444
{
4545
return new ReadOnlyDictionary<string, Identity>(developers);
4646
}

exercises/concept/authentication-system/AuthenticationSystemTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ public void GetAdmin()
1414
Assert.Equal(admin, authenticator.Admin);
1515
}
1616

17+
[Fact]
18+
[Task(4)]
19+
public void CheckAdminCannotBeTampered()
20+
{
21+
var adminEmail = "admin@ex.ism";
22+
var admin = new Identity { EyeColor = "green", Email = adminEmail };
23+
var authenticator = new Authenticator(admin);
24+
var tamperedAdmin = authenticator.Admin;
25+
tamperedAdmin.Email = "admin@hack.ed";
26+
Assert.Equal(adminEmail, authenticator.Admin.Email);
27+
}
28+
1729
[Fact]
1830
[Task(5)]
1931
public void GetDevelopers()
@@ -24,4 +36,15 @@ public void GetDevelopers()
2436
bool?[] expected = { true, true, true };
2537
Assert.Equal(expected, actual);
2638
}
39+
40+
[Fact]
41+
[Task(5)]
42+
public void CheckDevelopersCannotBeTampered()
43+
{
44+
var authenticator = new Authenticator(new Identity { EyeColor = "green", Email = "admin@ex.ism" });
45+
IDictionary<string, Identity> devs = authenticator.GetDevelopers();
46+
47+
Identity tamperedDev = new Identity { EyeColor = "grey", Email = "anders@hack.ed" };
48+
Assert.Throws<NotSupportedException>(() => devs["Anders"] = tamperedDev);
49+
}
2750
}

0 commit comments

Comments
 (0)