Skip to content

Commit 381b712

Browse files
authored
b/208718604 Allow choosing SSH key type (#596)
* Extend SSH settings object and apply policies * Extend SSH settings dialog pane * Extend ADMX to include SSH policies * Use configured key type when connecting
1 parent 3b7d454 commit 381b712

File tree

26 files changed

+927
-211
lines changed

26 files changed

+927
-211
lines changed

sources/Google.Solutions.Common.Test/Google.Solutions.Common.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<HintPath>..\packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath>
7878
</Reference>
7979
<Reference Include="System" />
80+
<Reference Include="System.ComponentModel.DataAnnotations" />
8081
<Reference Include="System.Configuration" />
8182
<Reference Include="System.Core" />
8283
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

sources/Google.Solutions.Common.Test/Util/TestEnumExtensions.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222
using Google.Solutions.Common.Util;
2323
using NUnit.Framework;
2424
using System;
25+
using System.ComponentModel.DataAnnotations;
2526

2627
namespace Google.Solutions.Common.Test.Util
2728
{
2829
[TestFixture]
2930
public class TestEnumExtensions : CommonFixtureBase
3031
{
32+
//---------------------------------------------------------------------
33+
// IsSingleFlag
34+
//---------------------------------------------------------------------
35+
3136
[Flags]
3237
public enum SampleFlags
3338
{
@@ -60,5 +65,32 @@ public void WhenTwoFlagsSet_ThenIsSingleFlagReturnsFalse()
6065
Assert.IsFalse(e.IsSingleFlag());
6166
Assert.IsTrue(e.IsFlagCombination());
6267
}
68+
69+
//---------------------------------------------------------------------
70+
// GetAttribute
71+
//---------------------------------------------------------------------
72+
73+
public enum SampleEnumWithAttributes
74+
{
75+
NoAttribute,
76+
77+
[Display(Name = "With attribute")]
78+
WithAttribute
79+
}
80+
81+
[Test]
82+
public void WhenValueHasAttribute_ThenGetAttributeReturnsValue()
83+
{
84+
var a = SampleEnumWithAttributes.WithAttribute.GetAttribute<DisplayAttribute>();
85+
Assert.IsNotNull(a);
86+
Assert.AreEqual("With attribute", a.Name);
87+
}
88+
89+
[Test]
90+
public void WhenValueHasNoAttribute_ThenGetAttributeReturnsNull()
91+
{
92+
var a = SampleEnumWithAttributes.NoAttribute.GetAttribute<DisplayAttribute>();
93+
Assert.IsNull(a);
94+
}
6395
}
6496
}

sources/Google.Solutions.Common/Util/EnumExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
// under the License.
2020
//
2121

22+
using System;
23+
using System.Linq;
24+
using System.Reflection;
25+
2226
namespace Google.Solutions.Common.Util
2327
{
2428
public static class EnumExtensions
@@ -40,5 +44,14 @@ public static bool IsFlagCombination<TEnum>(this TEnum enumValue)
4044
var v = (int)(object)enumValue;
4145
return v != 0 && !IsPowerOfTwo(v);
4246
}
47+
public static TAttribute GetAttribute<TAttribute>(this Enum enumValue)
48+
where TAttribute : Attribute
49+
{
50+
return enumValue
51+
.GetType()
52+
.GetMember(enumValue.ToString())
53+
.FirstOrDefault()?
54+
.GetCustomAttribute<TAttribute>();
55+
}
4356
}
4457
}

sources/Google.Solutions.IapDesktop.Application.Test/Services/Settings/TestApplicationSettingsRepository.cs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public class TestApplicationSettingsRepository : ApplicationFixtureBase
4040
[SetUp]
4141
public void SetUp()
4242
{
43-
hkcu.DeleteSubKeyTree(TestKeyPath, false);
44-
hkcu.DeleteSubKeyTree(TestMachinePolicyKeyPath, false);
45-
hkcu.DeleteSubKeyTree(TestUserPolicyKeyPath, false);
43+
this.hkcu.DeleteSubKeyTree(TestKeyPath, false);
44+
this.hkcu.DeleteSubKeyTree(TestMachinePolicyKeyPath, false);
45+
this.hkcu.DeleteSubKeyTree(TestUserPolicyKeyPath, false);
4646
}
4747

4848
[Test]
4949
public void WhenKeyEmpty_ThenDefaultsAreProvided()
5050
{
51-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
51+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
5252
{
5353
var repository = new ApplicationSettingsRepository(settingsKey, null, null);
5454

@@ -65,7 +65,7 @@ public void WhenKeyEmpty_ThenDefaultsAreProvided()
6565
[Test]
6666
public void WhenSettingsSaved_ThenSettingsCanBeRead()
6767
{
68-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
68+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
6969
{
7070
var repository = new ApplicationSettingsRepository(settingsKey, null, null);
7171

@@ -94,7 +94,7 @@ public void WhenSettingsSaved_ThenSettingsCanBeRead()
9494
[Test]
9595
public void WhenProxyUrlInvalid_ThenSetValueThrowsArgumentOutOfRangeException()
9696
{
97-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
97+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
9898
{
9999
var repository = new ApplicationSettingsRepository(settingsKey, null, null);
100100

@@ -109,9 +109,9 @@ public void WhenProxyUrlInvalid_ThenSetValueThrowsArgumentOutOfRangeException()
109109
[Test]
110110
public void WhenProxyUrlValidAndUserPolicySet_ThenPolicyWins()
111111
{
112-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
113-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
114-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
112+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
113+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
114+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
115115
{
116116
var repository = new ApplicationSettingsRepository(
117117
settingsKey,
@@ -130,9 +130,9 @@ public void WhenProxyUrlValidAndUserPolicySet_ThenPolicyWins()
130130
[Test]
131131
public void WhenProxyUrlValidAndMachinePolicySet_ThenPolicyWins()
132132
{
133-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
134-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
135-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
133+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
134+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
135+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
136136
{
137137
var repository = new ApplicationSettingsRepository(
138138
settingsKey,
@@ -151,9 +151,9 @@ public void WhenProxyUrlValidAndMachinePolicySet_ThenPolicyWins()
151151
[Test]
152152
public void WhenProxyUrlValidAndUserAndMachinePolicySet_ThenMachinePolicyWins()
153153
{
154-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
155-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
156-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
154+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
155+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
156+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
157157
{
158158
var repository = new ApplicationSettingsRepository(
159159
settingsKey,
@@ -177,7 +177,7 @@ public void WhenProxyUrlValidAndUserAndMachinePolicySet_ThenMachinePolicyWins()
177177
[Test]
178178
public void WhenProxyPacUrlInvalid_ThenSetValueThrowsArgumentOutOfRangeException()
179179
{
180-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
180+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
181181
{
182182
var repository = new ApplicationSettingsRepository(settingsKey, null, null);
183183

@@ -192,9 +192,9 @@ public void WhenProxyPacUrlInvalid_ThenSetValueThrowsArgumentOutOfRangeException
192192
[Test]
193193
public void WhenProxyPacUrlValidAndUserPolicySet_ThenPolicyWins()
194194
{
195-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
196-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
197-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
195+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
196+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
197+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
198198
{
199199
var repository = new ApplicationSettingsRepository(
200200
settingsKey,
@@ -213,9 +213,9 @@ public void WhenProxyPacUrlValidAndUserPolicySet_ThenPolicyWins()
213213
[Test]
214214
public void WhenProxyPacUrlValidAndMachinePolicySet_ThenPolicyWins()
215215
{
216-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
217-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
218-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
216+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
217+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
218+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
219219
{
220220
var repository = new ApplicationSettingsRepository(
221221
settingsKey,
@@ -234,9 +234,9 @@ public void WhenProxyPacUrlValidAndMachinePolicySet_ThenPolicyWins()
234234
[Test]
235235
public void WhenProxyPacUrlValidAndUserAndMachinePolicySet_ThenMachinePolicyWins()
236236
{
237-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
238-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
239-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
237+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
238+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
239+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
240240
{
241241
var repository = new ApplicationSettingsRepository(
242242
settingsKey,
@@ -260,7 +260,7 @@ public void WhenProxyPacUrlValidAndUserAndMachinePolicySet_ThenMachinePolicyWins
260260
[Test]
261261
public void WhenIsUpdateCheckEnabledValid_ThenSettingWins()
262262
{
263-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
263+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
264264
{
265265
var repository = new ApplicationSettingsRepository(
266266
settingsKey,
@@ -278,9 +278,9 @@ public void WhenIsUpdateCheckEnabledValid_ThenSettingWins()
278278
[Test]
279279
public void WhenIsUpdateCheckEnabledValidAndUserPolicySet_ThenPolicyWins()
280280
{
281-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
282-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
283-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
281+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
282+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
283+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
284284
{
285285
var repository = new ApplicationSettingsRepository(
286286
settingsKey,
@@ -299,9 +299,9 @@ public void WhenIsUpdateCheckEnabledValidAndUserPolicySet_ThenPolicyWins()
299299
[Test]
300300
public void WhenIsUpdateCheckEnabledValidAndMachinePolicySet_ThenPolicyWins()
301301
{
302-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
303-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
304-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
302+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
303+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
304+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
305305
{
306306
var repository = new ApplicationSettingsRepository(
307307
settingsKey,
@@ -320,9 +320,9 @@ public void WhenIsUpdateCheckEnabledValidAndMachinePolicySet_ThenPolicyWins()
320320
[Test]
321321
public void WhenIsUpdateCheckEnabledValidAndUserAndMachinePolicySet_ThenMachinePolicyWins()
322322
{
323-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
324-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
325-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
323+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
324+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
325+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
326326
{
327327
var repository = new ApplicationSettingsRepository(
328328
settingsKey,
@@ -346,7 +346,7 @@ public void WhenIsUpdateCheckEnabledValidAndUserAndMachinePolicySet_ThenMachineP
346346
[Test]
347347
public void WhenIsDeviceCertificateAuthenticationEnabledValid_ThenSettingWins()
348348
{
349-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
349+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
350350
{
351351
var repository = new ApplicationSettingsRepository(
352352
settingsKey,
@@ -364,9 +364,9 @@ public void WhenIsDeviceCertificateAuthenticationEnabledValid_ThenSettingWins()
364364
[Test]
365365
public void WhenIsDeviceCertificateAuthenticationEnabledValidAndUserPolicySet_ThenPolicyWins()
366366
{
367-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
368-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
369-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
367+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
368+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
369+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
370370
{
371371
var repository = new ApplicationSettingsRepository(
372372
settingsKey,
@@ -385,9 +385,9 @@ public void WhenIsDeviceCertificateAuthenticationEnabledValidAndUserPolicySet_Th
385385
[Test]
386386
public void WhenIsDeviceCertificateAuthenticationEnabledValidAndMachinePolicySet_ThenPolicyWins()
387387
{
388-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
389-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
390-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
388+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
389+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
390+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
391391
{
392392
var repository = new ApplicationSettingsRepository(
393393
settingsKey,
@@ -406,9 +406,9 @@ public void WhenIsDeviceCertificateAuthenticationEnabledValidAndMachinePolicySet
406406
[Test]
407407
public void WhenIsDeviceCertificateAuthenticationEnabledValidAndUserAndMachinePolicySet_ThenMachinePolicyWins()
408408
{
409-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
410-
using (var machinePolicyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
411-
using (var userPolicyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
409+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
410+
using (var machinePolicyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
411+
using (var userPolicyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
412412
{
413413
var repository = new ApplicationSettingsRepository(
414414
settingsKey,
@@ -432,7 +432,7 @@ public void WhenIsDeviceCertificateAuthenticationEnabledValidAndUserAndMachinePo
432432
[Test]
433433
public void WhenMachineAndUserPolicyKeysAreNull_ThenIsPolicyPresentReturnsFalse()
434434
{
435-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
435+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
436436
{
437437
var repository = new ApplicationSettingsRepository(settingsKey, null, null);
438438

@@ -443,8 +443,8 @@ public void WhenMachineAndUserPolicyKeysAreNull_ThenIsPolicyPresentReturnsFalse(
443443
[Test]
444444
public void WhenMachinePolicyKeyExists_ThenIsPolicyPresentReturnsTrue()
445445
{
446-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
447-
using (var policyKey = hkcu.CreateSubKey(TestMachinePolicyKeyPath))
446+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
447+
using (var policyKey = this.hkcu.CreateSubKey(TestMachinePolicyKeyPath))
448448
{
449449
var repository = new ApplicationSettingsRepository(settingsKey, policyKey, null);
450450

@@ -455,8 +455,8 @@ public void WhenMachinePolicyKeyExists_ThenIsPolicyPresentReturnsTrue()
455455
[Test]
456456
public void WhenUserPolicyKeyExists_ThenIsPolicyPresentReturnsTrue()
457457
{
458-
using (var settingsKey = hkcu.CreateSubKey(TestKeyPath))
459-
using (var policyKey = hkcu.CreateSubKey(TestUserPolicyKeyPath))
458+
using (var settingsKey = this.hkcu.CreateSubKey(TestKeyPath))
459+
using (var policyKey = this.hkcu.CreateSubKey(TestUserPolicyKeyPath))
460460
{
461461
var repository = new ApplicationSettingsRepository(settingsKey, null, policyKey);
462462

sources/Google.Solutions.IapDesktop.Application.Test/Views/Options/TestGeneralOptionsViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public void WhenSettingEnabled_ThenIsDeviceCertificateAuthenticationEnabledIsTru
205205
new HelpService());
206206

207207
Assert.IsTrue(viewModel.IsDeviceCertificateAuthenticationEnabled);
208+
Assert.IsTrue(viewModel.IsDeviceCertificateAuthenticationEditable);
208209
}
209210

210211
[Test]
@@ -221,10 +222,11 @@ public void WhenSettingDisabled_ThenIsDeviceCertificateAuthenticationEnabledIsTr
221222
new HelpService());
222223

223224
Assert.IsFalse(viewModel.IsDeviceCertificateAuthenticationEnabled);
225+
Assert.IsTrue(viewModel.IsDeviceCertificateAuthenticationEditable);
224226
}
225227

226228
[Test]
227-
public void WhenSettingEnabledByPolicy_ThenIsDeviceCertificateAuthenticationEeditableIsFalse()
229+
public void WhenSettingEnabledByPolicy_ThenIsDeviceCertificateAuthenticationEditableIsFalse()
228230
{
229231
var settingsRepository = CreateSettingsRepository(
230232
new Dictionary<string, object>

0 commit comments

Comments
 (0)