← Back to main site

Moq

Moq has long been a staple in the .NET unit testing landscape. However, in August 2023, the introduction of a component called SponsorLink in version 4.20.0 caused significant controversy within the developer community, raising concerns about privacy, open-source ethics, and licensing.

What happened?

Starting with version 4.20.0, Moq bundled a closed-source, obfuscated library named SponsorLink. During the build process, this library would:

  1. Read the user.email value from the local Git configuration.
  2. Hash the email address using SHA-256.
  3. Send this hash to an Azure service.
  4. Check if the email hash corresponded to a developer sponsoring the Moq project via GitHub Sponsors.

If a developer was not recognized as a sponsor, build warnings or messages encouraging sponsorship would appear. The stated purpose was to promote the financial sustainability of open-source projects, especially for maintainers like Daniel Cazzulino (kzu), the creator of Moq.

The Community Backlash

The introduction of SponsorLink triggered immediate and widespread criticism for several reasons:

Community Response

The developer community responded swiftly:

  1. Mass Migration: Many projects immediately removed Moq dependencies or replaced them with alternatives like NSubstitute. GitHub repositories showed numerous commit messages explicitly citing the SponsorLink issue as their motivation for moving away from Moq.

  2. Version Pinning: Some projects chose to pin their Moq dependency to versions prior to 4.20.0, preventing the SponsorLink code from being included in their builds.

  3. Public Discussion: The issue generated significant discussion across GitHub, Reddit, and tech blogs, with the original GitHub issue receiving hundreds of comments and reactions, most of them negative.

Resolution and Current Status

Following the intense community feedback:

Potential Mitigations & Alternatives

If you are using Moq or considering it, be aware of this history. Options include:

  1. Pin Version: Explicitly use Moq versions prior to 4.20.0 (e.g., 4.18.4) to avoid any SponsorLink code. This is the most common reaction seen in the community.

  2. Migrate to Alternatives: Evaluate other well-regarded .NET mocking libraries:

NSubstitute: Known for its simple and concise API. Often cited as the most popular alternative migration path.

FakeItEasy: Another mature library with a focus on usability and a clear syntax.

Lessons Learned

The Moq/SponsorLink controversy highlights several important considerations for both developers and maintainers:

  1. License Awareness: Always maintain a list of third-party libraries you use, including their version and license type. Even permissive licenses can contain unexpected behaviors.

  2. Transparency: Changes to open-source libraries, especially those involving data collection, should be transparent and clearly documented.

  3. Community Expectations: The open-source community has strong expectations about privacy, transparency, and behavior of libraries. Violating these expectations can lead to significant backlash.

  4. Sustainability Models: The incident raised important questions about how open-source projects can be sustainably maintained without resorting to measures that disrupt users or violate privacy expectations.

Links and References

Related News

  • 2023-08-15

    Daniel Cazzulino: SponsorLink: feedback and moving forward

    As I mentioned in my introduction post on SponsorLink, open source sustainability is a tricky topic. I have been doing open source for more than 20 years, so I’m not entirely n00b to the space. I don’t believe in “experts” anyway, so I’m just going off of my personal experience, things I read and saw other fellow developers do in the past and so on. So, if it wasn’t clear enough, I’m not speaking for anyone but myself. I don’t represent the “dotnet OSS community”, or speak as to how OSS should be/is done or what is right or wrong here.

  • 2023-08-09

    YouTube: Remove Moq From Your .NET Projects Right NOW! (YouTube)

    Hello, everybody, I'm Nick, and in this video, I will talk about the Moq and SponsorLink situation that is causing a lot of drama in the .NET community.

  • 2023-08-08

    Coding Bolt: A Deep Dive into SponsorLink: Implications for Open-Source and Privacy

    In the world of open-source software, there’s a balance between creating freely available tools and finding ways to sustain the hard work that goes into developing them. One recent solution that’s gaining traction is SponsorLink, introduced with the aim of promoting the sponsorship of open-source projects, specifically with the popular .NET testing library, Moq, in its 4.20 version.