Exemplo n.º 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
                                                                     ));
        });
    }
Exemplo n.º 2
0
 public void Locate_WithoutEnvironmentVariable_ReturnsNull()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internal.Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Null(EnvironmentLocator.LocateFromEnvironmentVariable());
     });
 }
Exemplo n.º 3
0
 public void GetCurrent_WithoutEnvironmentVariable_ReturnsNull()
 {
     EnvironmentVariableGuard.WithVariable(
         Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Null(EnvironmentLocator.GetCurrent());
     });
 }
Exemplo n.º 4
0
 public void GetCurrent_WithoutEnvironmentVariable_VersionOfEntryAssembly()
 {
     EnvironmentVariableGuard.WithVariable(
         Constants.ReleaseEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(Assembly.GetEntryAssembly()?.GetNameAndVersion().Version, ReleaseLocator.GetCurrent());
     });
 }
Exemplo n.º 5
0
 public void FindDsnOrDisable_NoEnvironmentVariableNorAttribute_ReturnsDisabledDsn()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         null,
         () =>
     {
         Assert.Equal(DisableSdkDsnValue, DsnLocator.FindDsnStringOrDisable());
     });
 }
Exemplo n.º 6
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         DisableSdkDsnValue,
         () =>
     {
         using (SentrySdk.Init())
             Assert.False(SentrySdk.IsEnabled);
     });
 }
Exemplo n.º 7
0
 public void Init_CallbackWithoutDsn_ValidDsnEnvironmentVariable_LocatesDsnEnvironmentVariable()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         ValidDsnWithSecret,
         () =>
     {
         using (SentrySdk.Init(c => { }))
             Assert.True(SentrySdk.IsEnabled);
     });
 }
Exemplo n.º 8
0
 public void Init_CallbackWithoutDsn_InvalidDsnEnvironmentVariable_DisabledSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         InvalidDsn,
         () =>
     {
         using (SentrySdk.Init(c => { }))
             Assert.False(SentrySdk.IsEnabled);
     });
 }
Exemplo n.º 9
0
 public void Init_DisableDsnEnvironmentVariable_DisablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         Sentry.Internals.Constants.DisableSdkDsnValue,
         () =>
     {
         SentryCore.Init();
         Assert.False(SentryCore.IsEnabled);
     });
 }
Exemplo n.º 10
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         Sentry.Internals.Constants.DsnEnvironmentVariable,
         DsnSamples.ValidDsnWithSecret,
         () =>
     {
         SentryCore.Init();
         Assert.True(SentryCore.IsEnabled);
     });
 }
Exemplo n.º 11
0
 public void Init_ValidDsnEnvironmentVariable_EnablesSdk()
 {
     EnvironmentVariableGuard.WithVariable(
         DsnEnvironmentVariable,
         ValidDsnWithSecret,
         () =>
     {
         using (SentrySdk.Init())
             Assert.True(SentrySdk.IsEnabled);
     });
 }
Exemplo n.º 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);
            });
        }
Exemplo n.º 14
0
        public void GetCurrent_WithEnvironmentVariable_VersionOfEnvironmentVariable()
        {
            const string expectedVersion = "the version";

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

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

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

            EnvironmentVariableGuard.WithVariable(
                DsnEnvironmentVariable,
                expected,
                () =>
            {
                Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable());
            });
        }
Exemplo n.º 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));
            });
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        });
    }
Exemplo n.º 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());
            });
Exemplo n.º 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));
            });
        }
Exemplo n.º 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
                                                                         ));
            });
        }