Beispiel #1
0
    public void Environment_BothOnOptionsAndEnvVar_ValueFromOption()
    {
        const string expected = "environment";
        const string other    = "other";

        Configure = o => o.Environment = expected;

        EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT",
                                              other,
                                              () =>
        {
            Build();
            _ = HttpClient.GetAsync("/throw").GetAwaiter().GetResult();

            _ = Worker.Received(1).EnqueueEnvelope(Arg.Is <Envelope>(e =>
                                                                     e.Items
                                                                     .Select(i => i.Payload)
                                                                     .OfType <JsonSerializable>()
                                                                     .Select(i => i.Source)
                                                                     .OfType <SentryEvent>()
                                                                     .Single()
                                                                     .Environment == expected
                                                                     ));
        });
    }
Beispiel #2
0
 public void Locate_WithoutEnvironmentVariable_ReturnsNull()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internal.Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Null(EnvironmentLocator.LocateFromEnvironmentVariable());
     });
 }
Beispiel #3
0
 public void GetCurrent_WithoutEnvironmentVariable_ReturnsNull()
 {
     EnvironmentVariableGuard.WithVariable(
         Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Null(EnvironmentLocator.GetCurrent());
     });
 }
Beispiel #4
0
 public void GetCurrent_WithoutEnvironmentVariable_VersionOfEntryAssembly()
 {
     EnvironmentVariableGuard.WithVariable(
         Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(Assembly.GetEntryAssembly()?.GetNameAndVersion().Version, ReleaseLocator.GetCurrent());
     });
 }
Beispiel #5
0
 public void FindDsnOrDisable_NoEnvironmentVariableNorAttribute_ReturnsDisabledDsn()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(DisableSdkDsnValue, DsnLocator.FindDsnStringOrDisable());
     });
 }
Beispiel #6
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         DisableSdkDsnValue,
         () =>
     {
         using (SentrySdk.Init())
             Assert.False(SentrySdk.IsEnabled);
     });
 }
Beispiel #7
0
 public void Init_CallbackWithoutDsn_ValidDsnEnvironmentVariable_LocatesDsnEnvironmentVariable()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         ValidDsnWithSecret,
         () =>
     {
         using (SentrySdk.Init(c => { }))
             Assert.True(SentrySdk.IsEnabled);
     });
 }
Beispiel #8
0
 public void Init_CallbackWithoutDsn_InvalidDsnEnvironmentVariable_DisabledSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         InvalidDsn,
         () =>
     {
         using (SentrySdk.Init(c => { }))
             Assert.False(SentrySdk.IsEnabled);
     });
 }
Beispiel #9
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         Sentry.Internals.Constants.DisableSdkDsnValue,
         () =>
     {
         SentryCore.Init();
         Assert.False(SentryCore.IsEnabled);
     });
 }
Beispiel #10
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         DsnSamples.ValidDsnWithSecret,
         () =>
     {
         SentryCore.Init();
         Assert.True(SentryCore.IsEnabled);
     });
 }
Beispiel #11
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         ValidDsnWithSecret,
         () =>
     {
         using (SentrySdk.Init())
             Assert.True(SentrySdk.IsEnabled);
     });
 }
Beispiel #12
0
    public void Locate_WithEnvironmentVariable_ReturnsEnvironmentVariableValue()
    {
        const string expectedVersion = "the environment name";

        EnvironmentVariableGuard.WithVariable(
            Sentry.Internal.Constants.EnvironmentEnvironmentVariable,
            expectedVersion,
            () =>
        {
            Assert.Equal(expectedVersion, EnvironmentLocator.LocateFromEnvironmentVariable());
        });
    }
        public void Current_CachesValue()
        {
            var expected = EnvironmentLocator.Current;

            EnvironmentVariableGuard.WithVariable(
                Sentry.Internal.Constants.ReleaseEnvironmentVariable,
                Guid.NewGuid().ToString(),
                () =>
            {
                Assert.Equal(expected, EnvironmentLocator.Current);
            });
        }
Beispiel #14
0
        public void GetCurrent_WithEnvironmentVariable_VersionOfEnvironmentVariable()
        {
            const string expectedVersion = "the version";

            EnvironmentVariableGuard.WithVariable(
                Constants.ReleaseEnvironmentVariable,
                expectedVersion,
                () =>
            {
                Assert.Equal(expectedVersion, ReleaseLocator.GetCurrent());
            });
        }
Beispiel #15
0
        public void ResolveFromEnvironment_WithEnvironmentVariable_VersionOfEnvironmentVariable()
        {
            const string expectedVersion = "the version";

            EnvironmentVariableGuard.WithVariable(
                Sentry.Internal.Constants.ReleaseEnvironmentVariable,
                expectedVersion,
                () =>
            {
                Assert.Equal(expectedVersion, ReleaseLocator.LocateFromEnvironment());
            });
        }
Beispiel #16
0
        public void GetCurrent_WithEnvironmentVariable_ReturnsEnvironmentVariableValue()
        {
            const string expectedVersion = "the environment name";

            EnvironmentVariableGuard.WithVariable(
                Constants.EnvironmentEnvironmentVariable,
                expectedVersion,
                () =>
            {
                Assert.Equal(expectedVersion, EnvironmentLocator.GetCurrent());
            });
        }
Beispiel #17
0
        [InlineData("Production")] // Custom setting which is the same as ASPNET_ENVIRONMENT. But because this is manually set, don't change it.
        public void Filters_Environment_SentryEnvironment_Set(string environment)
        {
            // Arrange.
            EnvironmentVariableGuard.WithVariable(Internal.Constants.EnvironmentEnvironmentVariable, environment, () =>
            {
                // Act.
                _sut.Configure(_target);

                // Assert.
                Assert.Equal(environment, _target.Environment);
            });
        }
Beispiel #18
0
 public void Init_InvalidDsnEnvironmentVariable_Throws()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         // If the variable was set, to non empty string but value is broken, better crash than silently disable
         InvalidDsn,
         () =>
     {
         var ex = Assert.Throws <ArgumentException>(() => SentrySdk.Init());
         Assert.Equal("Invalid DSN: A Project Id is required.", ex.Message);
     });
 }
Beispiel #19
0
        public void FindDsnOrDisable_DsnOnEnvironmentVariable_ReturnsTheDsn()
        {
            const string expected = DsnSamples.ValidDsnWithoutSecret;

            EnvironmentVariableGuard.WithVariable(
                DsnEnvironmentVariable,
                expected,
                () =>
            {
                Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable());
            });
        }
Beispiel #20
0
        public void FindDsnOrDisable_DsnOnEnvironmentVariableAndAttribute_ReturnsTheDsnFromEnvironmentVariable()
        {
            const string expected = DsnSamples.ValidDsnWithoutSecret;

            EnvironmentVariableGuard.WithVariable(
                DsnEnvironmentVariable,
                expected,
                () =>
            {
                var asm = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(DsnSamples.ValidDsnWithSecret);
                Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable(asm));
            });
        }
        public void Environment_NotOnOptions_ValueFromEnvVar()
        {
            const string expected = "environment";

            EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT",
                                                  expected,
                                                  () =>
            {
                Build();
                HttpClient.GetAsync("/throw").GetAwaiter().GetResult();

                Worker.Received(1).EnqueueEvent(Arg.Is <SentryEvent>(e => e.Environment == expected));
            });
        }
Beispiel #22
0
        [InlineData("aBcDe F !@#$ gHi", "aBcDe F !@#$ gHi")]       // Provided: nothing will change. (Case check)
        public void Process_NoEnvironmentOnOptions_SameAsEnvironmentVariable(string environment, string expectedEnvironment)
        {
            var sut = _fixture.GetSut();
            var evt = new SentryEvent();

            EnvironmentVariableGuard.WithVariable(
                Constants.EnvironmentEnvironmentVariable,
                environment,
                () =>
            {
                _ = sut.Process(evt);
            });

            Assert.Equal(expectedEnvironment, evt.Environment);
        }
        public void Process_NoEnvironmentOnOptions_SameAsEnvironmentVariable()
        {
            const string expected = "Staging";
            var          evt      = new SentryEvent();

            EnvironmentVariableGuard.WithVariable(
                Constants.EnvironmentEnvironmentVariable,
                expected,
                () =>
            {
                Sut.Process(evt);
            });

            Assert.Equal(expected, evt.Environment);
        }
Beispiel #24
0
    public void ConfigureLogging_ModifiesReleaseLocatorAndReadsKRevisionEnvVar_AppendsToRelease()
    {
        var sut = new SentryStartup();

        EnvironmentVariableGuard.WithVariable("K_REVISION", "9", () =>
        {
            sut.ConfigureLogging(WebHostBuilderContext, LoggingBuilder);

            var provider = LoggingBuilder.Services.BuildServiceProvider();
            var option   = provider.GetRequiredService <IOptions <SentryAspNetCoreOptions> >();

            Assert.Null(option.Value.Release);
            Assert.EndsWith("+9", ReleaseLocator.Resolve(option.Value));
        });
    }
Beispiel #25
0
        public void ResolveFromEnvironment_WithoutEnvironmentVariable_VersionOfEntryAssembly()
        {
            var ass = Assembly.GetEntryAssembly();

#if NET461
            Skip.If(ass == null, "GetEntryAssembly can return null on net461. eg on Mono or in certain test runners.");
#endif

            EnvironmentVariableGuard.WithVariable(
                Sentry.Internal.Constants.ReleaseEnvironmentVariable,
                null,
                () =>
            {
                Assert.Equal(
                    $"{ass!.GetName().Name}@{ass!.GetNameAndVersion().Version}",
                    ReleaseLocator.LocateFromEnvironment());
            });
Beispiel #26
0
        public void ResolveFromEnvironment_WithoutEnvironmentVariable_VersionOfEntryAssembly()
        {
#if NET461
            Skip.If(Runtime.Current.IsMono(), "GetEntryAssembly returning null on Mono.");
#endif
            var ass = Assembly.GetEntryAssembly();

            EnvironmentVariableGuard.WithVariable(
                Sentry.Internal.Constants.ReleaseEnvironmentVariable,
                null,
                () =>
            {
                Assert.Equal(
                    $"{ass!.GetName().Name}@{ass!.GetNameAndVersion().Version}",
                    ReleaseLocator.LocateFromEnvironment()
                    );
            });
        public void Environment_BothOnOptionsAndEnvVar_ValueFromOption()
        {
            const string expected = "environment";
            const string other    = "other";

            Configure = o => o.Environment = expected;

            EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT",
                                                  other,
                                                  () =>
            {
                Build();
                HttpClient.GetAsync("/throw").GetAwaiter().GetResult();

                Worker.Received(1).EnqueueEvent(Arg.Is <SentryEvent>(e => e.Environment == expected));
            });
        }
Beispiel #28
0
        public void Environment_NotOnOptions_ValueFromEnvVar()
        {
            const string expected = "environment";

            EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT",
                                                  expected,
                                                  () =>
            {
                Build();
                _ = HttpClient.GetAsync("/throw").GetAwaiter().GetResult();

                _ = Worker.Received(1).EnqueueEnvelope(Arg.Is <Envelope>(e =>
                                                                         e.Items
                                                                         .Select(i => i.Payload)
                                                                         .OfType <SentryEvent>()
                                                                         .Single()
                                                                         .Environment == expected
                                                                         ));
            });
        }