Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/test/objectPolicy.test.ts
4772 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ObjectPolicy } from '../policies/objectPolicy.ts';
8
import { type LanguageTranslations, PolicyType } from '../policies/types.ts';
9
import type { CategoryDto, PolicyDto } from '../policies/policyDto.ts';
10
11
suite('ObjectPolicy', () => {
12
const mockCategory: CategoryDto = {
13
key: 'test.category',
14
name: { value: 'Category1', key: 'test.category' },
15
};
16
17
const mockPolicy: PolicyDto = {
18
key: 'test.object.policy',
19
name: 'TestObjectPolicy',
20
category: 'Category1',
21
minimumVersion: '1.0',
22
type: 'object',
23
localization: {
24
description: { key: 'test.policy.description', value: 'Test policy description' }
25
}
26
};
27
28
test('should create ObjectPolicy from factory method', () => {
29
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
30
31
assert.ok(policy);
32
assert.strictEqual(policy.name, 'TestObjectPolicy');
33
assert.strictEqual(policy.minimumVersion, '1.0');
34
assert.strictEqual(policy.category.name.nlsKey, mockCategory.name.key);
35
assert.strictEqual(policy.category.name.value, mockCategory.name.value);
36
assert.strictEqual(policy.type, PolicyType.Object);
37
});
38
39
test('should render ADMX elements correctly', () => {
40
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
41
42
assert.ok(policy);
43
44
const admx = policy.renderADMX('TestKey');
45
46
assert.deepStrictEqual(admx, [
47
'<policy name="TestObjectPolicy" class="Both" displayName="$(string.TestObjectPolicy)" explainText="$(string.TestObjectPolicy_test_policy_description)" key="Software\\Policies\\Microsoft\\TestKey" presentation="$(presentation.TestObjectPolicy)">',
48
'\t<parentCategory ref="test.category" />',
49
'\t<supportedOn ref="Supported_1_0" />',
50
'\t<elements>',
51
'<multiText id="TestObjectPolicy" valueName="TestObjectPolicy" required="true" />',
52
'\t</elements>',
53
'</policy>'
54
]);
55
});
56
57
test('should render ADML strings correctly', () => {
58
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
59
60
assert.ok(policy);
61
62
const admlStrings = policy.renderADMLStrings();
63
64
assert.deepStrictEqual(admlStrings, [
65
'<string id="TestObjectPolicy">TestObjectPolicy</string>',
66
'<string id="TestObjectPolicy_test_policy_description">Test policy description</string>'
67
]);
68
});
69
70
test('should render ADML strings with translations', () => {
71
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
72
73
assert.ok(policy);
74
75
const translations: LanguageTranslations = {
76
'': {
77
'test.policy.description': 'Translated description'
78
}
79
};
80
81
const admlStrings = policy.renderADMLStrings(translations);
82
83
assert.deepStrictEqual(admlStrings, [
84
'<string id="TestObjectPolicy">TestObjectPolicy</string>',
85
'<string id="TestObjectPolicy_test_policy_description">Translated description</string>'
86
]);
87
});
88
89
test('should render ADML presentation correctly', () => {
90
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
91
92
assert.ok(policy);
93
94
const presentation = policy.renderADMLPresentation();
95
96
assert.strictEqual(presentation, '<presentation id="TestObjectPolicy"><multiTextBox refId="TestObjectPolicy" /></presentation>');
97
});
98
99
test('should render JSON value correctly', () => {
100
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
101
102
assert.ok(policy);
103
104
const jsonValue = policy.renderJsonValue();
105
106
assert.strictEqual(jsonValue, '');
107
});
108
109
test('should render profile value correctly', () => {
110
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
111
112
assert.ok(policy);
113
114
const profileValue = policy.renderProfileValue();
115
116
assert.strictEqual(profileValue, '<string></string>');
117
});
118
119
test('should render profile correctly', () => {
120
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
121
122
assert.ok(policy);
123
124
const profile = policy.renderProfile();
125
126
assert.strictEqual(profile.length, 2);
127
assert.strictEqual(profile[0], '<key>TestObjectPolicy</key>');
128
assert.strictEqual(profile[1], '<string></string>');
129
});
130
131
test('should render profile manifest value correctly', () => {
132
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
133
134
assert.ok(policy);
135
136
const manifestValue = policy.renderProfileManifestValue();
137
138
assert.strictEqual(manifestValue, '<key>pfm_default</key>\n<string></string>\n<key>pfm_description</key>\n<string>Test policy description</string>\n<key>pfm_name</key>\n<string>TestObjectPolicy</string>\n<key>pfm_title</key>\n<string>TestObjectPolicy</string>\n<key>pfm_type</key>\n<string>string</string>\n');
139
});
140
141
test('should render profile manifest value with translations', () => {
142
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
143
144
assert.ok(policy);
145
146
const translations: LanguageTranslations = {
147
'': {
148
'test.policy.description': 'Translated manifest description'
149
}
150
};
151
152
const manifestValue = policy.renderProfileManifestValue(translations);
153
154
assert.strictEqual(manifestValue, '<key>pfm_default</key>\n<string></string>\n<key>pfm_description</key>\n<string>Translated manifest description</string>\n<key>pfm_name</key>\n<string>TestObjectPolicy</string>\n<key>pfm_title</key>\n<string>TestObjectPolicy</string>\n<key>pfm_type</key>\n<string>string</string>\n');
155
});
156
157
test('should render profile manifest correctly', () => {
158
const policy = ObjectPolicy.from(mockCategory, mockPolicy);
159
160
assert.ok(policy);
161
162
const manifest = policy.renderProfileManifest();
163
164
assert.strictEqual(manifest, '<dict>\n<key>pfm_default</key>\n<string></string>\n<key>pfm_description</key>\n<string>Test policy description</string>\n<key>pfm_name</key>\n<string>TestObjectPolicy</string>\n<key>pfm_title</key>\n<string>TestObjectPolicy</string>\n<key>pfm_type</key>\n<string>string</string>\n\n</dict>');
165
});
166
});
167
168