question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extend AssemblyAssertions with methods to check on assemblies being signed or not

See original GitHub issue

Background and motivation

To ensure that the public key of an signed assembly does not accidentally changes, having an assertion .HavePublicKey(string) can help. For completeness/symmetry reasons adding .BeUnsigned() might be beneficial too.

API Proposal

public class AssemblyAssertions : ReferenceTypeAssertions<Assembly, AssemblyAssertions>
{
    public AndConstraint<AssemblyAssertions> NotHavePublicKey(string because = "", params object[] becauseArgs);

    public AndConstraint<AssemblyAssertions> HavePublicKey(string publicKey, string because = "", params object[] becauseArgs);
}

API Usage

var signed = typeof(AssemblyA.ClassA).Assembly;
signed.Should().HavePublicKey("sdfds");

var unsigned = typeof(AssemblyB.ClassB).Assembly;
unsigned.Should().NotHavePublicKey();

Alternative Designs

No response

Risks

No response

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Cornielcommented, Jun 8, 2023

I see the reasoning behind .NotHavePublicKey vs .HavePublicKey. That being said, from a test a specification perspective, someAssembly.Should().BeUnsigned() tells the story better than someAssembly.Should().NotHavePublicKey(). The latter hints to something like someAssembly.Should().NotHavePublicKey("InvalidKey").

For me .HavePublicKey(key) is short for .BeSignedWithPublicKey(key), or .BeSignedWith(key), hence my original proposal.

1reaction
jnyrupcommented, Jun 8, 2023

I’ve updated the proposal with the approved API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to unit testing delay-sign assemblies using nunit
If we test those assemblies using nunit (GUI version), the test won't work (all tests are failed) because of delay-signed. But if those ......
Read more >
Asserting Permissions in Custom Assemblies - SQL
Learn how to assert permissions so you can implement a custom assembly that makes secured calls to protected resources within your security ...
Read more >
C# static code analysis: Assemblies should be marked with ...
This rule raises an issue when an assembly contains a ResX -based resource but does not have the System.Resources.NeutralResourcesLanguageAttribute applied to ...
Read more >
Understanding How Assert Effects Security
Assert is a security action that is evaluated at run time. Code Access Permission classes and Permission Sets support a method called Assert...
Read more >
Using Assertions to Enhance the Correctness of Kmelia ...
The main idea is, first to con- sider a part of the Kmelia specification involved in the property to be verified (a service,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found