Skip to content

Commit 1b599d8

Browse files
committed
Fixed #19 Already set valid api key is overwritten with default api key
1 parent 1565ebd commit 1b599d8

File tree

6 files changed

+40
-49
lines changed

6 files changed

+40
-49
lines changed

Source/Extras/Extensions/ExceptionlessExtraConfigurationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ public static void ReadFromConfigSection(this ExceptionlessConfiguration config)
9090
config.Enabled = section.Enabled;
9191

9292
// Only update if it is not null
93-
if (!String.IsNullOrEmpty(section.ApiKey))
93+
if (!String.IsNullOrEmpty(section.ApiKey) && section.ApiKey != "API_KEY_HERE")
9494
config.ApiKey = section.ApiKey;
9595

9696
// If an appsetting is present for ApiKey, then it will override the other api keys
9797
string apiKeyOverride = ConfigurationManager.AppSettings["Exceptionless:ApiKey"] ?? String.Empty;
98-
if (!String.IsNullOrEmpty(apiKeyOverride))
98+
if (!String.IsNullOrEmpty(apiKeyOverride) && apiKeyOverride != "API_KEY_HERE")
9999
config.ApiKey = apiKeyOverride;
100100

101101
if (!String.IsNullOrEmpty(section.ServerUrl))

Source/Platforms/Log4net/BufferingExceptionlessAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override void ActivateOptions() {
2121
return;
2222

2323
_client = new ExceptionlessClient(config => {
24-
if (!String.IsNullOrEmpty(ApiKey))
24+
if (!String.IsNullOrEmpty(ApiKey) && ApiKey != "API_KEY_HERE")
2525
config.ApiKey = ApiKey;
2626
if (!String.IsNullOrEmpty(ServerUrl))
2727
config.ServerUrl = ServerUrl;

Source/Platforms/Log4net/ExceptionlessAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public override void ActivateOptions() {
1414
return;
1515

1616
_client = new ExceptionlessClient(config => {
17-
if (!String.IsNullOrEmpty(ApiKey))
17+
if (!String.IsNullOrEmpty(ApiKey) && ApiKey != "API_KEY_HERE")
1818
config.ApiKey = ApiKey;
1919
if (!String.IsNullOrEmpty(ServerUrl))
2020
config.ServerUrl = ServerUrl;

Source/Platforms/NLog/ExceptionlessTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected override void InitializeTarget() {
2424

2525
if (!String.IsNullOrEmpty(ApiKey) || !String.IsNullOrEmpty(ServerUrl))
2626
_client = new ExceptionlessClient(config => {
27-
if (!String.IsNullOrEmpty(ApiKey))
27+
if (!String.IsNullOrEmpty(ApiKey) && ApiKey != "API_KEY_HERE")
2828
config.ApiKey = ApiKey;
2929
if (!String.IsNullOrEmpty(ServerUrl))
3030
config.ServerUrl = ServerUrl;

Source/Shared/Extensions/ExceptionlessConfigurationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ public static void ReadFromAttributes(this ExceptionlessConfiguration config, IC
111111

112112
config.Enabled = attr.Enabled;
113113

114-
if (attr.ApiKey != null)
114+
if (!String.IsNullOrEmpty(attr.ApiKey) && attr.ApiKey != "API_KEY_HERE")
115115
config.ApiKey = attr.ApiKey;
116-
if (attr.ServerUrl != null)
116+
if (!String.IsNullOrEmpty(attr.ServerUrl))
117117
config.ServerUrl = attr.ServerUrl;
118118

119119
config.EnableSSL = attr.EnableSSL;

Source/Tests/ExceptionlessClientTests.cs

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,40 @@
11
using System;
2-
using System.Linq;
32
using System.Threading.Tasks;
4-
using Exceptionless;
5-
using Exceptionless.Dependency;
63
using Exceptionless.Models;
7-
using Exceptionless.Storage;
8-
using Foundatio.Metrics;
9-
using Foundatio.Queues;
10-
using Microsoft.Owin.Hosting;
11-
using SimpleInjector;
124
using Xunit;
135

146
namespace Exceptionless.Tests {
157
public class ExceptionlessClientTests {
16-
//private ExceptionlessClient CreateClient() {
17-
// return new ExceptionlessClient(c => {
18-
// c.ApiKey = DataHelper.TEST_API_KEY;
19-
// c.ServerUrl = Settings.Current.BaseURL;
20-
// c.EnableSSL = false;
21-
// c.UseDebugLogger();
22-
// c.UserAgent = "testclient/1.0.0.0";
23-
// });
24-
//}
25-
26-
//[Fact]
27-
//public async Task CanAddMultipleDataObjectsToEvent() {
28-
// var client = CreateClient();
29-
// var ev = client.CreateLog("Test");
30-
// Assert.Equal(ev.Target.Type, Event.KnownTypes.Log);
31-
// ev.AddObject(new Person { Name = "Blake" });
32-
// ev.AddObject(new Person { Name = "Eric" });
33-
// ev.AddObject(new Person { Name = "Ryan" });
34-
// Assert.Equal(ev.Target.Data.Count, 3);
35-
36-
// ev.Target.Data.Clear();
37-
// Assert.Equal(ev.Target.Data.Count, 0);
38-
39-
// // The last one in wins.
40-
// ev.AddObject(new Person { Name = "Eric" }, "Blake");
41-
// ev.AddObject(new Person { Name = "Blake" }, "Blake");
42-
// Assert.Equal(ev.Target.Data.Count, 1);
43-
44-
// var person = ev.Target.Data["Blake"].ToString();
45-
// Assert.True(person.Contains("Blake"));
46-
//}
8+
private ExceptionlessClient CreateClient() {
9+
return new ExceptionlessClient(c => {
10+
c.EnableSSL = false;
11+
c.UseDebugLogger();
12+
c.ReadFromAttributes();
13+
c.UserAgent = "testclient/1.0.0.0";
14+
});
15+
}
16+
17+
[Fact]
18+
public async Task CanAddMultipleDataObjectsToEvent() {
19+
var client = CreateClient();
20+
var ev = client.CreateLog("Test");
21+
Assert.Equal(ev.Target.Type, Event.KnownTypes.Log);
22+
ev.AddObject(new Person { Name = "Blake" });
23+
ev.AddObject(new Person { Name = "Eric" });
24+
ev.AddObject(new Person { Name = "Ryan" });
25+
Assert.Equal(ev.Target.Data.Count, 3);
26+
27+
ev.Target.Data.Clear();
28+
Assert.Equal(ev.Target.Data.Count, 0);
29+
30+
// The last one in wins.
31+
ev.AddObject(new Person { Name = "Eric" }, "Blake");
32+
ev.AddObject(new Person { Name = "Blake" }, "Blake");
33+
Assert.Equal(ev.Target.Data.Count, 1);
34+
35+
var person = ev.Target.Data["Blake"].ToString();
36+
Assert.True(person.Contains("Blake"));
37+
}
4738

4839
//[Fact]
4940
//public async Task CanSubmitSimpleEvent() {
@@ -52,10 +43,10 @@ public class ExceptionlessClientTests {
5243
// var queue = container.GetInstance<IQueue<EventPost>>();
5344
// Assert.NotNull(queue);
5445
// Assert.Equal(0, queue.GetQueueCount());
55-
46+
5647
// var statsCounter = container.GetInstance<IMetricsClient>() as InMemoryMetricsClient;
5748
// Assert.NotNull(statsCounter);
58-
49+
5950
// EnsureSampleData(container);
6051

6152
// var client = CreateClient();
@@ -102,7 +93,7 @@ public class ExceptionlessClientTests {
10293
// var storage = client.Configuration.Resolver.GetFileStorage() as InMemoryObjectStorage;
10394
// Assert.NotNull(storage);
10495
// Assert.Equal(1, storage.GetObjectList().Count());
105-
96+
10697
// Assert.True(statsCounter.WaitForCounter(MetricNames.EventsProcessed, work: client.ProcessQueue));
10798

10899
// Assert.Equal(0, queue.GetQueueCount());

0 commit comments

Comments
 (0)