Beispiel #1
0
        public void ToString_SameAsInput()
        {
            var @case = new DsnTestCase();
            var dsn   = Dsn.Parse(@case);

            Assert.Equal(@case.ToString(), dsn.ToString());
        }
Beispiel #2
0
        public void Ctor_ValidDsn_CorrectlyConstructs()
        {
            var @case = new DsnTestCase();
            var dsn   = Dsn.Parse(@case);

            AssertEqual(@case, dsn);
        }
        public IBackgroundWorker CreateBackgroundWorker()
        {
            if (_options.BackgroundWorker is { } worker)
            {
                _options.DiagnosticLogger?.LogDebug("Using IBackgroundWorker set through options: {0}.",
                                                    worker.GetType().Name);

                return(worker);
            }

            if (_options.Dsn is null)
            {
                throw new InvalidOperationException("The DSN is expected to be set at this point.");
            }

            var dsn = Dsn.Parse(_options.Dsn);

            var addAuth = SentryHeaders.AddSentryAuth(
                _options.SentryVersion,
                _options.ClientVersion,
                dsn.PublicKey,
                dsn.SecretKey
                );

            if (_options.SentryHttpClientFactory is {})
Beispiel #4
0
        public void Ctor_MissingScheme_ThrowsUriFormatException()
        {
            var @case = new DsnTestCase {
                Scheme = null
            };
            var ex = Assert.Throws <UriFormatException>(() => Dsn.Parse(@case));

            Assert.Equal("Invalid URI: The format of the URI could not be determined.", ex.Message);
        }
Beispiel #5
0
        public void Ctor_FutureScheme_ValidDsn()
        {
            var @case = new DsnTestCase {
                Scheme = "hypothetical"
            };
            var dsn = Dsn.Parse(@case);

            AssertEqual(@case, dsn);
        }
Beispiel #6
0
        public void Ctor_EmptyPath_ValidDsn()
        {
            var @case = new DsnTestCase {
                Path = string.Empty
            };
            var dsn = Dsn.Parse(@case);

            AssertEqual(@case, dsn);
        }
Beispiel #7
0
        public void Ctor_MissingSecretKey_GetterReturnsNull()
        {
            var @case = new DsnTestCase {
                SecretKey = null
            };
            var sut = Dsn.Parse(@case);

            Assert.Null(sut.SecretKey);
        }
Beispiel #8
0
        public void Ctor_InvalidHost_ThrowsUriFormatException()
        {
            var @case = new DsnTestCase {
                Host = null
            };
            var ex = Assert.Throws <UriFormatException>(() => Dsn.Parse(@case));

            Assert.Equal("Invalid URI: The hostname could not be parsed.", ex.Message);
        }
Beispiel #9
0
        public void Ctor_InvalidPort_ThrowsUriFormatException()
        {
            var @case = new DsnTestCase {
                Port = -1
            };
            var ex = Assert.Throws <UriFormatException>(() => Dsn.Parse(@case));

            Assert.Equal("Invalid URI: Invalid port specified.", ex.Message);
        }
Beispiel #10
0
        public void Ctor_MissingProjectId_ThrowsArgumentException()
        {
            var @case = new DsnTestCase {
                ProjectId = null
            };
            var ex = Assert.Throws <ArgumentException>(() => Dsn.Parse(@case));

            Assert.Equal("Invalid DSN: A Project Id is required.", ex.Message);
        }
Beispiel #11
0
        public void Ctor_MissingPublicAndSecretKey_ThrowsArgumentException()
        {
            var @case = new DsnTestCase {
                PublicKey = null, SecretKey = null, UserInfoSeparator = null, CredentialSeparator = null
            };
            var ex = Assert.Throws <ArgumentException>(() => Dsn.Parse(@case));

            Assert.Equal("Invalid DSN: No public key provided.", ex.Message);
        }
            public Fixture()
            {
                var uri = Dsn.Parse(DsnSamples.ValidDsnWithSecret).GetStoreEndpointUri();

                Message = new HttpRequestMessage(HttpMethod.Post, uri)
                {
                    Content = new StringContent(new string('a', MessageCharCount))
                };
            }
Beispiel #13
0
        internal HttpRequestMessage CreateRequest(Envelope envelope)
        {
            if (string.IsNullOrWhiteSpace(_options.Dsn))
            {
                throw new InvalidOperationException("The DSN is expected to be set at this point.");
            }

            var dsn = Dsn.Parse(_options.Dsn);

            var request = new HttpRequestMessage
            {
                RequestUri = dsn.GetEnvelopeEndpointUri(),
                Method     = HttpMethod.Post,
                Content    = new SerializableHttpContent(envelope)
            };

            _addAuth(request.Headers);
            return(request);
        }
        public void CreateRequest_SentryUrl_FromOptions()
        {
            // Arrange
            var httpTransport = new HttpTransport(
                new SentryOptions {
                Dsn = DsnSamples.ValidDsnWithSecret
            },
                new HttpClient());

            var envelope = Envelope.FromEvent(new SentryEvent());

            var uri = Dsn.Parse(DsnSamples.ValidDsnWithSecret).GetEnvelopeEndpointUri();

            // Act
            var request = httpTransport.CreateRequest(envelope);

            // Assert
            request.RequestUri.Should().Be(uri);
        }
        internal HttpRequestMessage CreateRequest(Envelope envelope)
        {
            if (string.IsNullOrWhiteSpace(_options.Dsn))
            {
                throw new InvalidOperationException("The DSN is expected to be set at this point.");
            }

            var dsn = Dsn.Parse(_options.Dsn);

            var authHeader =
                $"Sentry sentry_version={_options.SentryVersion}," +
                $"sentry_client={_options.ClientVersion}," +
                $"sentry_key={dsn.PublicKey}," +
                (dsn.SecretKey is { } secretKey ? $"sentry_secret={secretKey}," : null) +
                $"sentry_timestamp={_clock.GetUtcNow().ToUnixTimeSeconds()}";

            return(new HttpRequestMessage
            {
                RequestUri = dsn.GetEnvelopeEndpointUri(),
                Method = HttpMethod.Post,
                Headers = { { "X-Sentry-Auth", authHeader } },
                Content = new EnvelopeHttpContent(envelope)
            });
        }
Beispiel #16
0
        public void Ctor_NotUri_ThrowsUriFormatException()
        {
            var ex = Assert.Throws <UriFormatException>(() => Dsn.Parse("Not a URI"));

            Assert.Equal("Invalid URI: The format of the URI could not be determined.", ex.Message);
        }
Beispiel #17
0
        public void Ctor_EmptyStringDsn_ThrowsUriFormatException()
        {
            var ex = Assert.Throws <UriFormatException>(() => Dsn.Parse(string.Empty));

            Assert.Equal("Invalid URI: The URI is empty.", ex.Message);
        }
Beispiel #18
0
 public void Ctor_NullDsn_ThrowsArgumentNull()
 {
     _ = Assert.Throws <ArgumentNullException>(() => Dsn.Parse(null));
 }
Beispiel #19
0
        public void Ctor_SampleValidDsnWithSecret_CorrectlyConstructs()
        {
            var dsn = Dsn.Parse(DsnSamples.ValidDsnWithSecret);

            Assert.Equal(DsnSamples.ValidDsnWithSecret, dsn.ToString());
        }
Beispiel #20
0
        public void Ctor_DisableSdk_ThrowsUriFormatException()
        {
            var ex = Assert.Throws <UriFormatException>(() => Dsn.Parse(Constants.DisableSdkDsnValue));

            Assert.Equal("Invalid URI: The URI is empty.", ex.Message);
        }