public void TestSignatureValid_GivenValidSignature_Succeeds()
        {
            var token = LicenseKeyManager.Create(new SimpleTestLicense())
                        .CreateAndSignLicense(new LicenseSigningParameters());

            Assert.True(token.SignatureValid());
        }
示例#2
0
        public void Test_GenerateAndReadLicense_Normal_Succeeds()
        {
            using var parameters = new LicenseSigningParameters();

            var license = LicenseKeyManager.Create(new SimpleTestLicense())
                          .CreateAndSignLicense(parameters);

            var validationResults = LicenseKeyManager.Load <SimpleTestLicense>(license)
                                    .Validate();

            Assert.False(validationResults.HasErrors);
        }
        public void TestSignatureValid_GivenInvalidSignature_Fails()
        {
            var token = LicenseKeyManager.Create(new SimpleTestLicense())
                        .CreateAndSignLicense(new LicenseSigningParameters());

            var newSignature = new byte[2048 / 8];

            RandomNumberGenerator.Fill(newSignature);

            token = new SignedLicense(token.LicenseData, newSignature);

            Assert.False(token.SignatureValid());
        }
示例#4
0
        public void Test_GenerateAndReadLicense_BadSigningParameters_Fails()
        {
            using var originalParameters = new LicenseSigningParameters();

            var license = LicenseKeyManager.Create(new SimpleTestLicense())
                          .CreateAndSignLicense(originalParameters);

            using var newParameters = new LicenseSigningParameters();
            license = new SignedLicense(license.LicenseData, newParameters.PublicKey);

            Assert.Throws <InvalidOperationException>(
                () => LicenseKeyManager.Load <SimpleTestLicense>(license)
                .Validate());
        }
示例#5
0
        public void Test_GenerateAndReadLicense_ExportAndImport_Succeeds()
        {
            try
            {
                using var parameters = new LicenseSigningParameters();

                parameters.Export("lic.dat");
                using var importedParameters = LicenseSigningParameters.Import("lic.dat");

                var license = LicenseKeyManager.Create(new SimpleTestLicense())
                              .CreateAndSignLicense(importedParameters);

                var results = LicenseKeyManager.Load <SimpleTestLicense>(license)
                              .Validate();

                Assert.False(results.HasErrors);
            }
            finally
            {
                File.Delete("lic.dat");
            }
        }
示例#6
0
 public void TestCanCreateFactory_GivenNoModel()
 => Assert.NotNull(LicenseKeyManager.Create());
示例#7
0
 public void TestCanLoadSignedLicense_GivenBlankLicense()
 => Assert.NotNull(
     LicenseKeyManager.Load <SimpleTestLicense>(
         LicenseKeyManager.Create(new SimpleTestLicense())
         .CreateAndSignLicense(new LicenseSigningParameters())));
示例#8
0
 public void TestCanLoadSignedLicense_GivenSignedLicense()
 => Assert.NotNull(
     LicenseKeyManager.Load(
         LicenseKeyManager.Create()
         .CreateAndSignLicense(new LicenseSigningParameters())));
示例#9
0
 public void TestCanCreateFactory_GiveLicenseModel()
 => Assert.NotNull(LicenseKeyManager.Create(new SimpleTestLicense()));