コード例 #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
                                                                     ));
        });
    }
コード例 #2
0
 public void Locate_WithoutEnvironmentVariable_ReturnsNull()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internal.Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Null(EnvironmentLocator.LocateFromEnvironmentVariable());
     });
 }
コード例 #3
0
 public void GetCurrent_WithoutEnvironmentVariable_ReturnsNull()
 {
     EnvironmentVariableGuard.WithVariable(
         Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Null(EnvironmentLocator.GetCurrent());
     });
 }
コード例 #4
0
 public void GetCurrent_WithoutEnvironmentVariable_VersionOfEntryAssembly()
 {
     EnvironmentVariableGuard.WithVariable(
         Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(Assembly.GetEntryAssembly()?.GetNameAndVersion().Version, ReleaseLocator.GetCurrent());
     });
 }
コード例 #5
0
 public void FindDsnOrDisable_NoEnvironmentVariableNorAttribute_ReturnsDisabledDsn()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(DisableSdkDsnValue, DsnLocator.FindDsnStringOrDisable());
     });
 }
コード例 #6
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         DisableSdkDsnValue,
         () =>
     {
         using (SentrySdk.Init())
             Assert.False(SentrySdk.IsEnabled);
     });
 }
コード例 #7
0
 public void Init_CallbackWithoutDsn_ValidDsnEnvironmentVariable_LocatesDsnEnvironmentVariable()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         ValidDsnWithSecret,
         () =>
     {
         using (SentrySdk.Init(c => { }))
             Assert.True(SentrySdk.IsEnabled);
     });
 }
コード例 #8
0
 public void Init_CallbackWithoutDsn_InvalidDsnEnvironmentVariable_DisabledSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         InvalidDsn,
         () =>
     {
         using (SentrySdk.Init(c => { }))
             Assert.False(SentrySdk.IsEnabled);
     });
 }
コード例 #9
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         Sentry.Internals.Constants.DisableSdkDsnValue,
         () =>
     {
         SentryCore.Init();
         Assert.False(SentryCore.IsEnabled);
     });
 }
コード例 #10
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         DsnSamples.ValidDsnWithSecret,
         () =>
     {
         SentryCore.Init();
         Assert.True(SentryCore.IsEnabled);
     });
 }
コード例 #11
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         ValidDsnWithSecret,
         () =>
     {
         using (SentrySdk.Init())
             Assert.True(SentrySdk.IsEnabled);
     });
 }
コード例 #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());
        });
    }
コード例 #13
0
        public void Current_CachesValue()
        {
            var expected = EnvironmentLocator.Current;

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

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

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

            EnvironmentVariableGuard.WithVariable(
                Constants.EnvironmentEnvironmentVariable,
                expectedVersion,
                () =>
            {
                Assert.Equal(expectedVersion, EnvironmentLocator.GetCurrent());
            });
        }
コード例 #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);
            });
        }
コード例 #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);
     });
 }
コード例 #19
0
        public void FindDsnOrDisable_DsnOnEnvironmentVariable_ReturnsTheDsn()
        {
            const string expected = DsnSamples.ValidDsnWithoutSecret;

            EnvironmentVariableGuard.WithVariable(
                DsnEnvironmentVariable,
                expected,
                () =>
            {
                Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable());
            });
        }
コード例 #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));
            });
        }
コード例 #21
0
        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));
            });
        }
コード例 #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);
        }
コード例 #23
0
        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);
        }
コード例 #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));
        });
    }
コード例 #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());
            });
コード例 #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()
                    );
            });
コード例 #27
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).EnqueueEvent(Arg.Is <SentryEvent>(e => e.Environment == expected));
            });
        }
コード例 #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
                                                                         ));
            });
        }