This commit is contained in:
@@ -50,7 +50,7 @@ namespace AyaNova.Biz
|
|||||||
InventoryFull | AccountingFull | TechLimited | TechFull | SubContractorLimited |
|
InventoryFull | AccountingFull | TechLimited | TechFull | SubContractorLimited |
|
||||||
SubContractorFull | ClientLimited | ClientFull | OpsAdminLimited | OpsAdminFull
|
SubContractorFull | ClientLimited | ClientFull | OpsAdminLimited | OpsAdminFull
|
||||||
|
|
||||||
}//end SecurityLevelTypes
|
}//end AuthorizationRoles
|
||||||
|
|
||||||
}//end namespace GZTW.AyaNova.BLL
|
}//end namespace GZTW.AyaNova.BLL
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ namespace AyaNova.Biz
|
|||||||
//CREATE
|
//CREATE
|
||||||
internal async Task<User> CreateAsync(User inObj)
|
internal async Task<User> CreateAsync(User inObj)
|
||||||
{
|
{
|
||||||
|
//This is a new user so it will have been posted with a password in plaintext which needs to be salted and hashed
|
||||||
|
inObj.Salt = Hasher.GenerateSalt();
|
||||||
|
inObj.Password = Hasher.hash(inObj.Salt, inObj.Password);
|
||||||
|
|
||||||
Validate(inObj, true);
|
Validate(inObj, true);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return null;
|
return null;
|
||||||
@@ -44,6 +48,8 @@ namespace AyaNova.Biz
|
|||||||
//do stuff with User
|
//do stuff with User
|
||||||
User outObj = inObj;
|
User outObj = inObj;
|
||||||
outObj.OwnerId = userId;
|
outObj.OwnerId = userId;
|
||||||
|
|
||||||
|
|
||||||
//SearchHelper(break down text fields, save to db)
|
//SearchHelper(break down text fields, save to db)
|
||||||
//TagHelper(collection of tags??)
|
//TagHelper(collection of tags??)
|
||||||
await ct.User.AddAsync(outObj);
|
await ct.User.AddAsync(outObj);
|
||||||
@@ -317,8 +323,8 @@ namespace AyaNova.Biz
|
|||||||
AddError(ValidationErrorType.InvalidValue, "Roles");
|
AddError(ValidationErrorType.InvalidValue, "Roles");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Name must be less than 255 characters
|
//Optional employee number field must be less than 255 characters
|
||||||
if (inObj.EmployeeNumber.Length > 255)
|
if (!string.IsNullOrWhiteSpace(inObj.EmployeeNumber) && inObj.EmployeeNumber.Length > 255)
|
||||||
AddError(ValidationErrorType.LengthExceeded, "EmployeeNumber", "255 max");
|
AddError(ValidationErrorType.LengthExceeded, "EmployeeNumber", "255 max");
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ namespace AyaNova.Models
|
|||||||
public string Login { get; set; }
|
public string Login { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
[Required]
|
|
||||||
public string Salt { get; set; }
|
public string Salt { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public AuthorizationRoles Roles { get; set; }
|
public AuthorizationRoles Roles { get; set; }
|
||||||
|
|||||||
@@ -15,44 +15,40 @@ namespace raven_integration
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async void CRUD()
|
public async void CRUD()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
{
|
|
||||||
"id": 0,
|
|
||||||
"name": "string",
|
|
||||||
"dollarAmount": 0,
|
|
||||||
"active": true,
|
|
||||||
"roles": 0
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//CREATE
|
//CREATE
|
||||||
dynamic w1 = new JObject();
|
dynamic d1 = new JObject();
|
||||||
w1.name = Util.Uniquify("First Test User");
|
d1.name = Util.Uniquify("First Test User");
|
||||||
w1.dollarAmount = 1.11m;
|
d1.ownerId = 1L;
|
||||||
w1.active = true;
|
d1.active=true;
|
||||||
w1.roles = 0;
|
d1.login=Util.Uniquify("LOGIN");
|
||||||
|
d1.password=Util.Uniquify("PASSWORD");
|
||||||
|
d1.roles=0;//norole
|
||||||
|
d1.localeId=1;//random locale
|
||||||
|
d1.userType=3;//non scheduleable
|
||||||
|
|
||||||
ApiResponse r1 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), w1.ToString());
|
ApiResponse r1 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), d1.ToString());
|
||||||
Util.ValidateDataReturnResponseOk(r1);
|
Util.ValidateDataReturnResponseOk(r1);
|
||||||
long w1Id = r1.ObjectResponse["result"]["id"].Value<long>();
|
long d1Id = r1.ObjectResponse["result"]["id"].Value<long>();
|
||||||
|
|
||||||
|
|
||||||
dynamic w2 = new JObject();
|
dynamic d2 = new JObject();
|
||||||
w2.name = Util.Uniquify("Second Test User");
|
d2.name = Util.Uniquify("Second Test User");
|
||||||
w2.dollarAmount = 2.22m;
|
d2.dollarAmount = 2.22m;
|
||||||
w2.active = true;
|
d2.active = true;
|
||||||
w2.roles = 0;
|
d2.roles = 0;
|
||||||
|
|
||||||
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
ApiResponse r2 = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), d2.ToString());
|
||||||
Util.ValidateDataReturnResponseOk(r2);
|
Util.ValidateDataReturnResponseOk(r2);
|
||||||
long w2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
long d2Id = r2.ObjectResponse["result"]["id"].Value<long>();
|
||||||
|
|
||||||
|
|
||||||
//RETRIEVE
|
//RETRIEVE
|
||||||
|
|
||||||
//Get one
|
//Get one
|
||||||
ApiResponse r3 = await Util.GetAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
ApiResponse r3 = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||||
Util.ValidateDataReturnResponseOk(r3);
|
Util.ValidateDataReturnResponseOk(r3);
|
||||||
r3.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
r3.ObjectResponse["result"]["name"].Value<string>().Should().Be(d2.name.ToString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -60,31 +56,31 @@ namespace raven_integration
|
|||||||
//PUT
|
//PUT
|
||||||
|
|
||||||
//update w2id
|
//update w2id
|
||||||
w2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
d2.name = Util.Uniquify("UPDATED VIA PUT SECOND TEST User");
|
||||||
w2.OwnerId = 1;
|
d2.OwnerId = 1;
|
||||||
w2.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
d2.concurrencyToken = r2.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||||
ApiResponse PUTTestResponse = await Util.PutAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), w2.ToString());
|
ApiResponse PUTTestResponse = await Util.PutAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), d2.ToString());
|
||||||
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
Util.ValidateHTTPStatusCode(PUTTestResponse, 200);
|
||||||
|
|
||||||
//check PUT worked
|
//check PUT worked
|
||||||
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
ApiResponse checkPUTWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||||
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
Util.ValidateNoErrorInResponse(checkPUTWorked);
|
||||||
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(w2.name.ToString());
|
checkPUTWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(d2.name.ToString());
|
||||||
uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
uint concurrencyToken = PUTTestResponse.ObjectResponse["result"]["concurrencyToken"].Value<uint>();
|
||||||
|
|
||||||
//PATCH
|
//PATCH
|
||||||
var newName = Util.Uniquify("UPDATED VIA PATCH SECOND TEST User");
|
var newName = Util.Uniquify("UPDATED VIA PATCH SECOND TEST User");
|
||||||
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]";
|
||||||
ApiResponse PATCHTestResponse = await Util.PatchAsync("User/" + w2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"), patchJson);
|
ApiResponse PATCHTestResponse = await Util.PatchAsync("User/" + d2Id.ToString() + "/" + concurrencyToken.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"), patchJson);
|
||||||
Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
|
Util.ValidateHTTPStatusCode(PATCHTestResponse, 200);
|
||||||
|
|
||||||
//check PATCH worked
|
//check PATCH worked
|
||||||
ApiResponse checkPATCHWorked = await Util.GetAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
ApiResponse checkPATCHWorked = await Util.GetAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||||
Util.ValidateNoErrorInResponse(checkPATCHWorked);
|
Util.ValidateNoErrorInResponse(checkPATCHWorked);
|
||||||
checkPATCHWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(newName);
|
checkPATCHWorked.ObjectResponse["result"]["name"].Value<string>().Should().Be(newName);
|
||||||
|
|
||||||
//DELETE
|
//DELETE
|
||||||
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + w2Id.ToString(), await Util.GetTokenAsync( "manager", "l3tm3in"));
|
ApiResponse DELETETestResponse = await Util.DeleteAsync("User/" + d2Id.ToString(), await Util.GetTokenAsync("manager", "l3tm3in"));
|
||||||
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
Util.ValidateHTTPStatusCode(DELETETestResponse, 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,31 +114,6 @@ namespace raven_integration
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test server exception
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
public async void ServerExceptionShouldErrorPropertly()
|
|
||||||
{
|
|
||||||
//Get non existant
|
|
||||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
|
||||||
ApiResponse a = await Util.GetAsync("User/exception", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
||||||
Util.ValidateServerExceptionResponse(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Test server alt exception
|
|
||||||
/// </summary>
|
|
||||||
[Fact]
|
|
||||||
public async void ServerAltExceptionShouldErrorPropertly()
|
|
||||||
{
|
|
||||||
//Get non existant
|
|
||||||
//Should return status code 400, api error code 2200 and a first target in details of "id"
|
|
||||||
ApiResponse a = await Util.GetAsync("User/altexception", await Util.GetTokenAsync( "manager", "l3tm3in"));
|
|
||||||
Util.ValidateServerExceptionResponse(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user