Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 1e176ec

Browse files
committed
Merge branch 'develop' into upstream-develop
2 parents 880137e + cc6649b commit 1e176ec

File tree

6 files changed

+91
-16
lines changed

6 files changed

+91
-16
lines changed

src/SymphonyOSS.RestApiClient/Authentication/AppSessionManager.cs

+4-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class AppSessionManager : ISessionManager
3131

3232
private string _appSessionToken;
3333
private string _userSessionToken;
34-
private string _username;
34+
private readonly string _username;
3535

3636
public AppSessionManager(string sessionAuthUrl, X509Certificate2 appCertificate, string username)
3737
{
@@ -42,7 +42,7 @@ public AppSessionManager(string sessionAuthUrl, X509Certificate2 appCertificate,
4242
_sessionAuthApi = sessionAuthApiFactory.CreateAuthenticationApi(appCertificate);
4343
}
4444

45-
public AppSessionManager(IAuthenticationApi sessionAuthApi, IAuthenticationApi keyAuthApi, X509Certificate2 certificate)
45+
public AppSessionManager(IAuthenticationApi sessionAuthApi, X509Certificate2 certificate)
4646
{
4747
Certificate = certificate;
4848
_sessionAuthApi = sessionAuthApi;
@@ -59,17 +59,11 @@ public string SessionToken
5959
GenerateTokens();
6060
}
6161

62-
return _appSessionToken;
62+
return _userSessionToken;
6363
}
6464
}
6565

66-
public string KeyManagerToken
67-
{
68-
get
69-
{
70-
return null;
71-
}
72-
}
66+
public string KeyManagerToken => null;
7367

7468
/// <summary>
7569
/// Generates both the session and key manager tokens.
@@ -81,8 +75,6 @@ public void GenerateTokens()
8175

8276
_appSessionToken = _sessionAuthApi.V1AppAuthenticatePost()._Token;
8377
_userSessionToken = _sessionAuthApi.V1AppUsernameUsernameAuthenticatePost(_username, _appSessionToken)._Token;
84-
8578
}
86-
8779
}
8880
}

src/SymphonyOSS.RestApiClient/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("0.3.0.0")]
37-
[assembly: AssemblyInformationalVersion("0.3.0")]
36+
[assembly: AssemblyFileVersion("0.3.1.0")]
37+
[assembly: AssemblyInformationalVersion("0.3.1")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Licensed to the Symphony Software Foundation (SSF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SSF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
namespace SymphonyOSS.RestApiClient.Tests
19+
{
20+
using Authentication;
21+
using Generated.OpenApi.AuthenticatorApi.Api;
22+
using Generated.OpenApi.AuthenticatorApi.Model;
23+
using Moq;
24+
using System.Security.Cryptography.X509Certificates;
25+
using Xunit;
26+
27+
public class AppSessionManagerTest
28+
{
29+
private readonly X509Certificate2 _certificate;
30+
31+
private readonly Mock<IAuthenticationApi> _sessionAuthApiMock;
32+
33+
public AppSessionManagerTest()
34+
{
35+
_certificate = new Mock<X509Certificate2>().Object;
36+
_sessionAuthApiMock = new Mock<IAuthenticationApi>();
37+
}
38+
39+
[Fact]
40+
public void EnsureTokens_are_returned_without_explicitly_calling_GenerateTokens()
41+
{
42+
_sessionAuthApiMock.Setup(obj => obj.V1AppAuthenticatePost()).Returns(new Token("appSessionToken", "as1"));
43+
_sessionAuthApiMock.Setup(obj => obj.V1AppUsernameUsernameAuthenticatePost(null, "as1")).Returns(new Token("userSessionToken", "us1"));
44+
var appSessionManager = new AppSessionManager(_sessionAuthApiMock.Object, _certificate);
45+
var sessionToken = appSessionManager.SessionToken;
46+
var keyManagerToken = appSessionManager.KeyManagerToken;
47+
Assert.Equal("as1", sessionToken);
48+
Assert.Null(keyManagerToken);
49+
}
50+
51+
[Fact]
52+
public void EnsureGenerateTokens_regenerate_tokens_every_call()
53+
{
54+
var sessionTokenCounter = 0;
55+
_sessionAuthApiMock.Setup(obj => obj.V1AppAuthenticatePost()).Returns(() =>
56+
{
57+
++sessionTokenCounter;
58+
return new Token("appSessionToken", "as" + sessionTokenCounter);
59+
});
60+
_sessionAuthApiMock.Setup(obj => obj.V1AppUsernameUsernameAuthenticatePost(null, It.IsAny<string>())).Returns(new Token("userSessionToken", "us1"));
61+
var appSessionManager = new AppSessionManager(_sessionAuthApiMock.Object, _certificate);
62+
Assert.Equal("as1", appSessionManager.SessionToken);
63+
Assert.Equal("as1", appSessionManager.SessionToken);
64+
Assert.Null(appSessionManager.KeyManagerToken);
65+
66+
appSessionManager.GenerateTokens();
67+
Assert.Equal("as2", appSessionManager.SessionToken);
68+
Assert.Null(appSessionManager.KeyManagerToken);
69+
}
70+
71+
}
72+
}

test/SymphonyOSS.RestApiClient.Tests/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("0.3.0.0")]
37-
[assembly: AssemblyInformationalVersion("0.3.0")]
36+
[assembly: AssemblyFileVersion("0.3.1.0")]
37+
[assembly: AssemblyInformationalVersion("0.3.1")]

test/SymphonyOSS.RestApiClient.Tests/SymphonyOSS.RestApiClient.Tests.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\packages\xunit.runner.visualstudio.2.2.0-beta2-build1149\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.2.0-beta2-build1149\build\net20\xunit.runner.visualstudio.props')" />
34
<PropertyGroup>
45
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
56
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -16,6 +17,8 @@
1617
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
1718
<IsCodedUITest>False</IsCodedUITest>
1819
<TestProjectType>UnitTest</TestProjectType>
20+
<NuGetPackageImportStamp>
21+
</NuGetPackageImportStamp>
1922
</PropertyGroup>
2023
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2124
<DebugSymbols>true</DebugSymbols>
@@ -104,6 +107,7 @@
104107
<Compile Include="RetryStrategyApiExecutorTest.cs" />
105108
<Compile Include="PodApiFactoryTest.cs" />
106109
<Compile Include="SessionApiTest.cs" />
110+
<Compile Include="AppSessionManagerTest.cs" />
107111
<Compile Include="UserSessionManagerTest.cs" />
108112
<Compile Include="StreamsApiTest.cs" />
109113
<Compile Include="SystemApiTest.cs" />
@@ -144,6 +148,12 @@
144148
</Choose>
145149
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
146150
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
151+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
152+
<PropertyGroup>
153+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
154+
</PropertyGroup>
155+
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.2.0-beta2-build1149\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.2.0-beta2-build1149\build\net20\xunit.runner.visualstudio.props'))" />
156+
</Target>
147157
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
148158
Other similar extension points exist, see Microsoft.Common.targets.
149159
<Target Name="BeforeBuild">

test/SymphonyOSS.RestApiClient.Tests/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
1010
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
1111
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
12+
<package id="xunit.runner.visualstudio" version="2.2.0-beta2-build1149" targetFramework="net45" developmentDependency="true" />
1213
</packages>

0 commit comments

Comments
 (0)