Skip to content

Commit 7b1d8c1

Browse files
author
gauffininteractive
committed
Merge branch 'master' into server-api-client
2 parents 14e527e + 7c0102e commit 7b1d8c1

File tree

11 files changed

+231
-160
lines changed

11 files changed

+231
-160
lines changed

src/Server/OneTrueError.Api.Client.Tests/TryTheClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public class TryTheClient
1717
public async Task Test()
1818
{
1919
OneTrueApiClient client = new OneTrueApiClient();
20-
client.Open(new Uri("http://localhost/onetrueerror/"), "o333", "kjsdklsdsdjkl");
20+
client.Open(new Uri("http://localhost/onetrueerror/"), "", "");
2121
FindAccountByUserNameResult result = null;
2222
try
2323
{
2424
result = await client.QueryAsync(new FindAccountByUserName("admin"));
2525
}
26-
catch (WebException ex)
26+
catch (WebException ex)
2727
{
2828

2929
}

src/Server/OneTrueError.Api/Core/ApiKeys/Commands/CreateApiKey.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel.Design;
23
using DotNetCqs;
34

45
namespace OneTrueError.Api.Core.ApiKeys.Commands
@@ -29,6 +30,32 @@ public CreateApiKey(string applicationName, string apiKey, string sharedSecret,
2930
ApplicationIds = applicationIds;
3031
}
3132

33+
/// <summary>
34+
/// Creates a new instance of <see cref="CreateApiKey"/>.
35+
/// </summary>
36+
/// <param name="applicationName"><see cref="ApplicationName"/></param>
37+
/// <param name="apiKey"><see cref="ApiKey"/></param>
38+
/// <param name="sharedSecret"><see cref="SharedSecret"/></param>
39+
public CreateApiKey(string applicationName, string apiKey, string sharedSecret)
40+
{
41+
if (applicationName == null) throw new ArgumentNullException("applicationName");
42+
if (apiKey == null) throw new ArgumentNullException("apiKey");
43+
if (sharedSecret == null) throw new ArgumentNullException("sharedSecret");
44+
45+
ApplicationName = applicationName;
46+
ApiKey = apiKey;
47+
SharedSecret = sharedSecret;
48+
ApplicationIds = new int[0];
49+
}
50+
51+
/// <summary>
52+
/// Serialization constructor
53+
/// </summary>
54+
protected CreateApiKey()
55+
{
56+
57+
}
58+
3259

3360
/// <summary>
3461
/// Must always be the one that creates the key (will be assigned by the CommandBus per convention)

src/Server/OneTrueError.App/Core/Accounts/Requests/ActivateAccountHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ public class ActivateAccountHandler : IRequestHandler<ActivateAccount, ActivateA
1818
{
1919
private readonly IEventBus _eventBus;
2020
private readonly IAccountRepository _repository;
21-
private IQueryBus _queryBus;
21+
private readonly IQueryBus _queryBus;
22+
2223
/// <summary>
2324
/// Creates a new instance of <see cref="ActivateAccountHandler" />.
2425
/// </summary>
2526
/// <param name="repository">repos</param>
2627
/// <param name="eventBus">used to publish <see cref="AccountActivated" />.</param>
28+
/// <param name="queryBus"> </param>
2729
public ActivateAccountHandler(IAccountRepository repository, IEventBus eventBus, IQueryBus queryBus)
2830
{
2931
_repository = repository;
@@ -51,7 +53,7 @@ public async Task<ActivateAccountReply> ExecuteAsync(ActivateAccount request)
5153
var query = new GetApplicationList();
5254
var apps = await _queryBus.QueryAsync(query);
5355
var roles = apps.Select(x => "Member_" + x.Id).ToArray();
54-
56+
5557
Thread.CurrentPrincipal = new OneTruePrincipal(account.Id, account.UserName, roles);
5658
var evt = new AccountActivated(account.Id, account.UserName)
5759
{

src/Server/OneTrueError.SqlServer.Tests/Core/ApiKeys/Commands/CreateApiKeyHandlerTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public async Task should_be_able_to_Create_key()
5252
generated.AllowedApplications.Should().BeEquivalentTo(new[] {_applicationId});
5353
}
5454

55+
[Fact]
56+
public async Task should_be_able_to_Create_a_key_without_applications_mapped()
57+
{
58+
var cmd = new CreateApiKey("Mofo", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));
59+
60+
var sut = new CreateApiKeyHandler(_uow);
61+
await sut.ExecuteAsync(cmd);
62+
63+
var repos = new ApiKeyRepository(_uow);
64+
var generated = await repos.GetByKeyAsync(cmd.ApiKey);
65+
generated.Should().NotBeNull();
66+
generated.AllowedApplications.Should().BeEmpty();
67+
}
68+
5569
public void Dispose()
5670
{
5771
_uow.Dispose();

src/Server/OneTrueError.SqlServer/Core/ApiKeys/Commands/CreateApiKeyHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public async Task ExecuteAsync(CreateApiKey command)
3333
id = (int) await cmd.ExecuteScalarAsync();
3434
}
3535

36+
3637
foreach (var applicationId in command.ApplicationIds)
3738
{
3839
using (var cmd = _unitOfWork.CreateDbCommand())

src/Server/OneTrueError.SqlServer/Schema/Database.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ BEGIN
119119
[CreatedAtUtc] DATETIME NOT NULL,
120120
[SolvedAtUtc] DATETIME NULL,
121121
[Title] NVARCHAR(100) NULL,
122-
[RemoteAddress] VARCHAR (20) NULL,
122+
[RemoteAddress] VARCHAR (45) NULL, --SEE http://stackoverflow.com/questions/166132/maximum-length-of-the-textual-representation-of-an-ipv6-address
123123
[Exception] NTEXT NOT NULL,
124124
[ContextInfo] NTEXT NOT NULL
125125
);

src/Server/OneTrueError.Web/Areas/Admin/Controllers/ApiKeysController.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public ApiKeysController(IQueryBus queryBus, ICommandBus commandBus)
2626

2727
public async Task<ActionResult> Index()
2828
{
29-
var query= new ListApiKeys();
29+
var query = new ListApiKeys();
3030
var result = await _queryBus.QueryAsync(query);
31-
var vms = result.Keys.Select(x => new ListViewModelItem {Id = x.Id, Name = x.ApplicationName}).ToArray();
32-
var model = new ListViewModel {Keys = vms};
31+
var vms = result.Keys.Select(x => new ListViewModelItem { Id = x.Id, Name = x.ApplicationName }).ToArray();
32+
var model = new ListViewModel { Keys = vms };
3333
return View(model);
3434
}
3535

@@ -81,11 +81,13 @@ public async Task<ActionResult> Create(CreateViewModel model)
8181

8282
var apiKey = Guid.NewGuid().ToString("N");
8383
var sharedSecret = Guid.NewGuid().ToString("N");
84-
var apps = model.SelectedApplications.Select(int.Parse).ToArray();
84+
var apps = model.SelectedApplications == null
85+
? new int[0]
86+
: model.SelectedApplications.Select(int.Parse).ToArray();
8587
var cmd = new CreateApiKey(model.ApplicationName, apiKey, sharedSecret, apps);
8688
await _commandBus.ExecuteAsync(cmd);
8789

88-
return RedirectToAction("Created", new {apiKey, sharedSecret});
90+
return RedirectToAction("Created", new { apiKey, sharedSecret });
8991
}
9092

9193
public ActionResult Created(string apiKey, string sharedSecret)

0 commit comments

Comments
 (0)