Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve tampering test on exercise "Authentication System" #2193

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/concept/authentication-system/.meta/Exemplar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Identity Admin
get { return new Identity { Email = admin.Email, EyeColor = admin.EyeColor }; }
}

public IReadOnlyDictionary<string, Identity> GetDevelopers()
public IDictionary<string, Identity> GetDevelopers()
{
return new ReadOnlyDictionary<string, Identity>(developers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ public void GetAdmin()
Assert.Equal(admin, authenticator.Admin);
}

[Fact]
[Task(4)]
public void CheckAdminCannotBeTampered()
{
var adminEmail = "admin@ex.ism";
var admin = new Identity { EyeColor = "green", Email = adminEmail };
var authenticator = new Authenticator(admin);
var tamperedAdmin = authenticator.Admin;
tamperedAdmin.Email = "admin@hack.ed";
Assert.Equal(adminEmail, authenticator.Admin.Email);
}

[Fact]
[Task(5)]
public void GetDevelopers()
Expand All @@ -24,4 +36,15 @@ public void GetDevelopers()
bool?[] expected = { true, true, true };
Assert.Equal(expected, actual);
}

[Fact]
[Task(5)]
public void CheckDevelopersCannotBeTampered()
{
var authenticator = new Authenticator(new Identity { EyeColor = "green", Email = "admin@ex.ism" });
IDictionary<string, Identity> devs = authenticator.GetDevelopers();

Identity tamperedDev = new Identity { EyeColor = "grey", Email = "anders@hack.ed" };
Assert.Throws<NotSupportedException>(() => devs["Anders"] = tamperedDev);
}
}
Loading