Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplicity signature #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions unity/Assets/Editor/CommonRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public void StrigthforwardCallShouldReturn_AuthRequired()
[Test]
[Category("BigTests")]
[MaxTime(10000)]
public void RestClient_GetShouldReturn_WrongSignature()
public void RestClient_IfKeyIsNotCorrect_GetShouldReturn_Forbidden()
{
RestClient client = new RestClient(
DEV.BASEURI, DEV.CLIENTID, DEV.APPID, DEV.APIKEY, DEV.APISECRET, DEV.SERVICE);
RestClient client = new RestClient(DEV.BASEURI, "-", "-", "-", "-", DEV.SERVICE);

Response response = null;

Expand All @@ -47,14 +46,14 @@ public void RestClient_GetShouldReturn_WrongSignature()

while (coroutine.MoveNext()) { ;}

Assert.AreEqual(401, response.StatusCode);
Assert.IsTrue(response.www.error.ToLowerInvariant().Contains("401 unauthorized"), response.www.error);
Assert.IsTrue(response.www.text.ToLowerInvariant().Contains("wrong signature"), response.www.text);
Assert.AreEqual(403, response.StatusCode);
Assert.AreEqual("403 Forbidden", response.www.error.Trim( new char[]{'\r','\n'} ));
}

[Test]
[Category("BigTests")]
[MaxTime(10000)]
[Ignore]
public void RestClient_PostShouldReturn_WrongSignature()
{
RestClient client = new RestClient(
Expand All @@ -68,16 +67,13 @@ public void RestClient_PostShouldReturn_WrongSignature()

while (coroutine.MoveNext()) { ;}

Assert.AreEqual(401, response.StatusCode);
Assert.AreEqual(400, response.StatusCode);
Assert.IsTrue(response.www.error.ToLowerInvariant().Contains("401 unauthorized"), response.www.error);
Assert.IsTrue(response.www.text.ToLowerInvariant().Contains("wrong signature"), response.www.text);
}

[Test]
[Category("BigTests")]
[MaxTime(10000)]
[Ignore]
public void RestClient_GetShouldReturn_200()

Response RequestCommonGet()
{
RestClient client = new RestClient(
DEV.BASEURI, DEV.CLIENTID, DEV.APPID, DEV.APIKEY, DEV.APISECRET, DEV.SERVICE);
Expand All @@ -92,8 +88,35 @@ public void RestClient_GetShouldReturn_200()

while (coroutine.MoveNext()) { ;}

return response;
}

[Test]
[Category("BigTests")]
[MaxTime(10000)]
public void RestClient_GetShouldReturn_200()
{
var response = RequestCommonGet();
Assert.AreEqual(200, response.StatusCode);
Assert.AreEqual("", response.www.error);
}


[Test]
[Category("BigTests")]
[MaxTime(10000)]
public void RestClient_GetShouldNotReturn_Error()
{
var response = RequestCommonGet();
Assert.AreEqual(null, response.www.error);
}

[Test]
[Category("BigTests")]
[MaxTime(10000)]
public void RestClient_GetShouldReturn_ValidData()
{
var response = RequestCommonGet();
Assert.AreEqual("[]", response.www.text);
}

}
Expand Down
Binary file modified unity/Assets/Leaderboard/Leaderboard.unity
Binary file not shown.
4 changes: 2 additions & 2 deletions unity/Assets/ScoreboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void Start()
/// <param name="callback">Callback method with Exception and TopScores args</param>
public void GetTop(Action<Exception, TopScores> callback)
{
Get<TopScores>("/v1/scoreboard/score/10", callback);
Get<TopScores>("/scoreboard/score/10", callback);
}

/// <summary>
Expand All @@ -32,6 +32,6 @@ public void GetTop(Action<Exception, TopScores> callback)
/// <param name="callback">Callback method with Exception and ScoreData args</param>
public void PostScore(ScoreData score, Action<Exception, ScoreData> callback)
{
Post<ScoreData>("/v1/scoreboard/score", score, callback);
Post<ScoreData>("/scoreboard/score", score, callback);
}
}
7 changes: 4 additions & 3 deletions unity/Assets/Utils/SignatureBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public string CredentialScope
{
// TODO: CredentialScope
//return string.Format("{0}/{1}/{2}/{3}/{4}", CLIENTID, APPID, APIKEY, APISECRET, svcname);
return string.Format("{0}/{1}", "20160619", svcname);
return string.Format("{0}/{1}", "_", svcname);
}
}

Expand All @@ -185,7 +185,8 @@ public string Signature
using (var hmac = new HMACSHA256(keyByte))
{
var hashBytes = hmac.ComputeHash(messageBytes);
return Convert.ToBase64String(hashBytes);//.TrimEnd('='); // TODO: trim is not needed
// TODO: figure out
return Convert.ToBase64String(hashBytes).Replace('+', '-').Replace('/', '_');
}
}
}
Expand All @@ -194,7 +195,7 @@ public string Credentials
{
get
{
return string.Format(CredentialsFormat, APIKEY, "20160619", svcname);
return string.Format(CredentialsFormat, APIKEY, "_", svcname);
}
}

Expand Down