Skip to content

Commit 794516b

Browse files
authored
Merge pull request #908 from PlayEveryWare/reauthtest
test: Auth/Connect while already logged in produces expected results
2 parents a0dae5b + 97a6cb6 commit 794516b

File tree

5 files changed

+228
-1
lines changed

5 files changed

+228
-1
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2024 PlayEveryWare
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
namespace PlayEveryWare.EpicOnlineServices.Tests.Auth
24+
{
25+
using Epic.OnlineServices;
26+
using Epic.OnlineServices.Achievements;
27+
using Epic.OnlineServices.Auth;
28+
using Epic.OnlineServices.Stats;
29+
using NUnit.Framework;
30+
using System.Collections;
31+
using UnityEngine;
32+
using UnityEngine.TestTools;
33+
34+
public class AuthenticationTests
35+
{
36+
GameObject eosObject;
37+
protected const float LoginTestTimeout = 30f;
38+
39+
[TearDown]
40+
public void ShutdownEOS()
41+
{
42+
EOSManager.Instance?.OnShutdown();
43+
UnityEngine.Object.Destroy(eosObject);
44+
}
45+
46+
/// <summary>
47+
/// This test creates a new EOSManager object, and uses it to auth-login.
48+
/// Then after a successful login, it tries to auth login again.
49+
/// The result should be as expected.
50+
/// </summary>
51+
/// <returns></returns>
52+
[UnityTest]
53+
public IEnumerator AuthLogin_WhileAlreadyLoggedIn_ReturnsExpectedResult()
54+
{
55+
eosObject = new GameObject();
56+
var eosManager = eosObject.AddComponent<EOSManager>();
57+
58+
UnitTestConfig config = EpicOnlineServices.Config.Get<UnitTestConfig>();
59+
60+
// Initial Auth login
61+
LoginCallbackInfo? loginResult = null;
62+
EOSManager.Instance.StartLoginWithLoginTypeAndToken(LoginCredentialType.Developer,
63+
$"{config.EOSDevAuthToolIP}:{config.EOSDevAuthToolPort}",
64+
config.EOSDevAuthToolUserName,
65+
data => { loginResult = data; });
66+
67+
yield return new EOSTestBase.WaitUntilDone(LoginTestTimeout, () => loginResult != null);
68+
69+
Assert.IsNotNull(loginResult,
70+
"Could not log into EOS, loginResult was not set.");
71+
72+
Assert.AreEqual(Result.Success, loginResult.Value.ResultCode,
73+
$"Login result failed: {loginResult.Value.ResultCode}");
74+
75+
// Subsequent Auth login
76+
loginResult = null;
77+
EOSManager.Instance.StartLoginWithLoginTypeAndToken(LoginCredentialType.Developer,
78+
$"{config.EOSDevAuthToolIP}:{config.EOSDevAuthToolPort}",
79+
config.EOSDevAuthToolUserName,
80+
data => { loginResult = data; });
81+
82+
yield return new EOSTestBase.WaitUntilDone(LoginTestTimeout, () => loginResult != null);
83+
84+
Assert.IsNotNull(loginResult,
85+
"Could not log into EOS, loginResult was not set.");
86+
87+
Assert.AreEqual(Result.Success, loginResult.Value.ResultCode,
88+
$"Login result failed: {loginResult.Value.ResultCode}");
89+
}
90+
}
91+
}

Assets/Tests/PlayMode/AuthenticationTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2024 PlayEveryWare
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
namespace PlayEveryWare.EpicOnlineServices.Tests.Connect
24+
{
25+
using Epic.OnlineServices;
26+
using Epic.OnlineServices.Achievements;
27+
using Epic.OnlineServices.Stats;
28+
using NUnit.Framework;
29+
using System.Collections;
30+
using UnityEngine;
31+
using UnityEngine.TestTools;
32+
33+
public class ConnectTests
34+
{
35+
GameObject eosObject;
36+
protected const float LoginTestTimeout = 30f;
37+
38+
[TearDown]
39+
public void ShutdownEOS()
40+
{
41+
EOSManager.Instance?.OnShutdown();
42+
UnityEngine.Object.Destroy(eosObject);
43+
}
44+
45+
/// <summary>
46+
/// This test creates a new EOSManager object, and uses it to auth-login.
47+
/// Then it does a Connect login.
48+
/// After a successful Connect login, it tries to perform another Connect login.
49+
/// The result should be as expected.
50+
/// </summary>
51+
/// <returns></returns>
52+
[UnityTest]
53+
public IEnumerator ConnectLogin_WhileAlreadyLoggedIn_ReturnsExpectedResult()
54+
{
55+
eosObject = new GameObject();
56+
var eosManager = eosObject.AddComponent<EOSManager>();
57+
58+
UnitTestConfig config = EpicOnlineServices.Config.Get<UnitTestConfig>();
59+
60+
// Auth login
61+
// This isn't what this test is testing, but we must first auth login before connect login
62+
Epic.OnlineServices.Auth.LoginCallbackInfo? loginResult = null;
63+
EOSManager.Instance.StartLoginWithLoginTypeAndToken(Epic.OnlineServices.Auth.LoginCredentialType.Developer,
64+
$"{config.EOSDevAuthToolIP}:{config.EOSDevAuthToolPort}",
65+
config.EOSDevAuthToolUserName,
66+
data => { loginResult = data; });
67+
68+
yield return new EOSTestBase.WaitUntilDone(LoginTestTimeout, () => loginResult != null);
69+
70+
Assert.IsNotNull(loginResult,
71+
"Could not log into EOS, loginResult was not set.");
72+
73+
Assert.AreEqual(Result.Success, loginResult.Value.ResultCode,
74+
$"Login result failed: {loginResult.Value.ResultCode}");
75+
76+
// Now that this is logged in, attempt connect login
77+
Epic.OnlineServices.Connect.LoginCallbackInfo? callbackInfo = null;
78+
EOSManager.Instance.StartConnectLoginWithEpicAccount(loginResult.Value.LocalUserId, data =>
79+
{
80+
callbackInfo = data;
81+
});
82+
83+
yield return new EOSTestBase.WaitUntilDone(LoginTestTimeout, () => callbackInfo != null);
84+
85+
Assert.IsNotNull(callbackInfo,
86+
"Could not connect with Epic account, callbackInfo was not set.");
87+
88+
Assert.AreEqual(Result.Success, callbackInfo.Value.ResultCode,
89+
$"Could not connect with Epic account: {callbackInfo.Value.ResultCode}");
90+
91+
Assert.That(EOSManager.Instance.GetProductUserId().IsValid(),
92+
"Current player is invalid.");
93+
94+
// Subsequent connect login, check for expected results
95+
callbackInfo = null;
96+
EOSManager.Instance.StartConnectLoginWithEpicAccount(loginResult.Value.LocalUserId, data =>
97+
{
98+
callbackInfo = data;
99+
});
100+
101+
yield return new EOSTestBase.WaitUntilDone(LoginTestTimeout, () => callbackInfo != null);
102+
103+
Assert.IsNotNull(callbackInfo,
104+
"Could not connect with Epic account, callbackInfo was not set.");
105+
106+
Assert.AreEqual(Result.Success, callbackInfo.Value.ResultCode,
107+
$"Could not connect with Epic account: {callbackInfo.Value.ResultCode}");
108+
109+
Assert.That(EOSManager.Instance.GetProductUserId().IsValid(),
110+
"Current player is invalid.");
111+
}
112+
}
113+
}

Assets/Tests/PlayMode/ConnectTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Tests/PlayMode/com.playeveryware.eos.tests.playmode.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"GUID:3a63500f0eef43a438c0553491f7c5da",
88
"GUID:0acc523941302664db1f4e527237feb3",
99
"GUID:27619889b8ba8c24980f49ee34dbb44a",
10-
"GUID:f4c43db447a22a645bb9364507e4ba6c"
10+
"GUID:f4c43db447a22a645bb9364507e4ba6c",
11+
"GUID:cc11d9857b82d9b458fca637d5cb33fb"
1112
],
1213
"includePlatforms": [],
1314
"excludePlatforms": [],

0 commit comments

Comments
 (0)