@oxy.so/app-preset 6.2.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -82,8 +82,10 @@ plugins: [
82
82
 
83
83
  This adds the iOS `keychain-access-groups` entitlement
84
84
  (`$(AppIdentifierPrefix)group.so.oxy.shared`; only Commons and the Peable wallet get
85
- more, and any other app naming `so.oxy.identity` or `so.oxy.wallet` fails prebuild —
86
- ADR 0062 of the oxy repo), the Oxy `expo-build-properties`
85
+ more, their `.dev` builds the `.dev` groups, and any other app naming `so.oxy.identity` or
86
+ `so.oxy.wallet` in any spelling fails prebuild — ADR 0062 of the oxy repo;
87
+ `oxy-check-keychain-entitlements <bundle-id> ios` runs the same policy over what prebuild
88
+ wrote), the Oxy `expo-build-properties`
87
89
  defaults (iOS `deploymentTarget 16.4`; Android ProGuard + resource shrinking — the
88
90
  Android compile/target SDK and build tools are the Expo SDK's own, never pinned here), and `@oxy.so/services/plugins/withOxySharedPermissions`:
89
91
  the app declares and requests the signature-level `so.oxy.permission.IDENTITY` and
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * oxy-check-keychain-entitlements — the keychain access-group policy
4
+ * (`plugin/oxyKeychainGroups.js`) run over entitlements that were actually
5
+ * WRITTEN, not over an app config: what `expo prebuild` left in `ios/`, or what
6
+ * a signed binary carries.
7
+ *
8
+ * oxy-check-keychain-entitlements <bundle-id> <path> [--team-id <TEAMID>]
9
+ *
10
+ * `<path>` is an entitlements plist (`.entitlements`, `.xcent`, the XML of
11
+ * `codesign -d --entitlements - --xml <app>`) or a directory searched for
12
+ * `*.entitlements` (an `ios/` folder after prebuild; `Pods`, `build` and
13
+ * `node_modules` are skipped). Every file found is checked. `--team-id` says
14
+ * the file is codesigned output of that team, whose entries are expanded
15
+ * (`<TEAMID>.so.oxy.wallet`, not `$(AppIdentifierPrefix)so.oxy.wallet`).
16
+ *
17
+ * Exits 0 when every file passes, 1 on a policy violation, 2 on a usage or
18
+ * read error. A directory with no entitlements file is an error: there was
19
+ * nothing to check.
20
+ */
21
+ const { readFileSync, readdirSync, statSync } = require('node:fs');
22
+ const { join, resolve } = require('node:path');
23
+ const { assertOxyKeychainGroups } = require('../plugin/oxyKeychainGroups');
24
+
25
+ const KEY = 'keychain-access-groups';
26
+ const SKIPPED_DIRS = new Set(['Pods', 'build', 'node_modules', 'DerivedData']);
27
+
28
+ class UsageError extends Error {}
29
+
30
+ /** `@expo/plist`, from the app first, then through Expo's own config plugins. */
31
+ function loadPlist(projectRoot = process.cwd()) {
32
+ const attempts = [
33
+ () => require.resolve('@expo/plist', { paths: [projectRoot] }),
34
+ () =>
35
+ require.resolve('@expo/plist', {
36
+ paths: [require.resolve('expo/config-plugins', { paths: [projectRoot] })],
37
+ }),
38
+ () => require.resolve('@expo/plist', { paths: [require.resolve('expo/config-plugins')] }),
39
+ () => require.resolve('@expo/plist'),
40
+ ];
41
+ for (const attempt of attempts) {
42
+ try {
43
+ const plist = require(attempt());
44
+ return plist.default ?? plist;
45
+ } catch {
46
+ // Try the next resolution.
47
+ }
48
+ }
49
+ throw new UsageError(
50
+ '@expo/plist could not be loaded: run this from an Expo app (expo installs it)',
51
+ );
52
+ }
53
+
54
+ /** The `keychain-access-groups` value of one entitlements plist. */
55
+ function readKeychainGroups(file, plist = loadPlist()) {
56
+ const text = readFileSync(file, 'utf8');
57
+ if (text.startsWith('bplist')) {
58
+ throw new UsageError(`${file} is a binary plist: convert it with \`plutil -convert xml1\``);
59
+ }
60
+ let parsed;
61
+ try {
62
+ parsed = plist.parse(text);
63
+ } catch (error) {
64
+ throw new UsageError(`${file} is not a readable plist: ${error.message}`);
65
+ }
66
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
67
+ throw new UsageError(`${file} is not an entitlements dictionary`);
68
+ }
69
+ return parsed[KEY];
70
+ }
71
+
72
+ /** Every `*.entitlements` under `dir`, sorted. */
73
+ function findEntitlements(dir) {
74
+ const found = [];
75
+ const walk = (current) => {
76
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
77
+ const path = join(current, entry.name);
78
+ if (entry.isDirectory()) {
79
+ if (!SKIPPED_DIRS.has(entry.name)) walk(path);
80
+ } else if (entry.isFile() && entry.name.endsWith('.entitlements')) {
81
+ found.push(path);
82
+ }
83
+ }
84
+ };
85
+ walk(dir);
86
+ return found.sort();
87
+ }
88
+
89
+ /**
90
+ * Check `target` for `bundleId`. Throws the policy's Error on a violation and
91
+ * a UsageError when there is nothing readable to check.
92
+ *
93
+ * @param {{ bundleId: string, target: string, teamId?: string, plist?: { parse(text: string): unknown } }} options
94
+ * @returns {{ file: string, groups: unknown }[]}
95
+ */
96
+ function checkKeychainEntitlements({ bundleId, target, teamId, plist }) {
97
+ const path = resolve(target);
98
+ let stats;
99
+ try {
100
+ stats = statSync(path);
101
+ } catch {
102
+ throw new UsageError(`${target} does not exist`);
103
+ }
104
+ const files = stats.isDirectory() ? findEntitlements(path) : [path];
105
+ if (files.length === 0) {
106
+ throw new UsageError(`no *.entitlements file under ${target}`);
107
+ }
108
+ const parser = plist ?? loadPlist();
109
+ return files.map((file) => {
110
+ const groups = readKeychainGroups(file, parser);
111
+ try {
112
+ assertOxyKeychainGroups(bundleId, groups, teamId === undefined ? {} : { teamId });
113
+ } catch (error) {
114
+ error.message = `${file}: ${error.message}`;
115
+ throw error;
116
+ }
117
+ return { file, groups };
118
+ });
119
+ }
120
+
121
+ function parseArgs(argv) {
122
+ const positional = [];
123
+ let teamId;
124
+ for (let i = 0; i < argv.length; i += 1) {
125
+ const arg = argv[i];
126
+ if (arg === '--team-id') {
127
+ teamId = argv[i + 1];
128
+ if (teamId === undefined) throw new UsageError('--team-id needs a value');
129
+ i += 1;
130
+ } else if (arg.startsWith('--team-id=')) {
131
+ teamId = arg.slice('--team-id='.length);
132
+ } else if (arg.startsWith('-')) {
133
+ throw new UsageError(`unknown option ${arg}`);
134
+ } else {
135
+ positional.push(arg);
136
+ }
137
+ }
138
+ if (positional.length !== 2) {
139
+ throw new UsageError(
140
+ 'usage: oxy-check-keychain-entitlements <bundle-id> <entitlements-file-or-ios-dir> [--team-id <TEAMID>]',
141
+ );
142
+ }
143
+ return { bundleId: positional[0], target: positional[1], teamId };
144
+ }
145
+
146
+ /** The CLI. Returns the exit code. */
147
+ function main(argv = process.argv.slice(2), { log = console.log, error = console.error } = {}) {
148
+ try {
149
+ const results = checkKeychainEntitlements(parseArgs(argv));
150
+ for (const { file, groups } of results) {
151
+ log(`ok ${file}: ${JSON.stringify(groups ?? [])}`);
152
+ }
153
+ return 0;
154
+ } catch (failure) {
155
+ error(failure.message);
156
+ return failure instanceof UsageError ? 2 : 1;
157
+ }
158
+ }
159
+
160
+ module.exports = {
161
+ checkKeychainEntitlements,
162
+ findEntitlements,
163
+ main,
164
+ readKeychainGroups,
165
+ UsageError,
166
+ };
167
+
168
+ if (require.main === module) {
169
+ process.exitCode = main();
170
+ }
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@oxy.so/app-preset",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
5
5
  "main": "./app.plugin.js",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
+ "bin": {
10
+ "oxy-check-keychain-entitlements": "./bin/oxy-check-keychain-entitlements.js"
11
+ },
9
12
  "exports": {
10
13
  ".": "./app.plugin.js",
11
14
  "./app.plugin.js": "./app.plugin.js",
12
15
  "./plugin/withOxyAppPreset": "./plugin/withOxyAppPreset.js",
13
16
  "./plugin/withOxyKeychain": "./plugin/withOxyKeychain.js",
17
+ "./plugin/oxyKeychainGroups": "./plugin/oxyKeychainGroups.js",
18
+ "./check-entitlements": "./bin/oxy-check-keychain-entitlements.js",
14
19
  "./plugin/withOxyBuildProperties": "./plugin/withOxyBuildProperties.js",
15
20
  "./plugin/withOxyAndroidRelease": "./plugin/withOxyAndroidRelease.js",
16
21
  "./plugin/withOxyAndroidWebp": "./plugin/withOxyAndroidWebp.js",
@@ -29,6 +34,7 @@
29
34
  "NOTICE",
30
35
  "app.plugin.js",
31
36
  "plugin",
37
+ "bin",
32
38
  "metro",
33
39
  "babel",
34
40
  "build-id",
@@ -2,11 +2,13 @@
2
2
  * Who may name which Oxy iOS keychain access group
3
3
  * (docs/identity/ios-keychain-access-groups.md, ADR 0062 in the oxy repo).
4
4
  *
5
- * | Group | Holders | Holds |
6
- * |------------------------|---------------------------------------|----------------------------------------|
7
- * | `so.oxy.identity` | Commons only, FIRST in its list | the personal root, phrases, org index |
8
- * | `so.oxy.wallet` | Commons, the Peable wallet | private keys the wallet signs with |
9
- * | `group.so.oxy.shared` | every Oxy app | public keys, the device-session credential |
5
+ * | Group | Holders | Holds |
6
+ * |------------------------|-------------------------------------------|----------------------------------------|
7
+ * | `so.oxy.identity` | Commons only, FIRST in its list | the personal root, phrases, org index |
8
+ * | `so.oxy.wallet` | Commons, the Peable wallet | private keys the wallet signs with |
9
+ * | `so.oxy.identity.dev` | Commons' DEV build only, FIRST | the same, for the dev build |
10
+ * | `so.oxy.wallet.dev` | the DEV builds of Commons and the wallet | the same, for the dev builds |
11
+ * | `group.so.oxy.shared` | every Oxy app | public keys, the device-session credential |
10
12
  *
11
13
  * The first entry of `keychain-access-groups` is the app's DEFAULT group, and
12
14
  * `@oxy.so/core` reads its role from it at runtime: identity first is Commons,
@@ -14,6 +16,20 @@
14
16
  * ORDER is part of the policy, not only the membership: Commons lists
15
17
  * `[identity, wallet, shared]`, the Peable wallet `[wallet, shared]`.
16
18
  *
19
+ * The DEV builds (`so.oxy.commons.dev`, `to.peable.app.dev`) sit next to the
20
+ * production apps on the same phone, are signed by the same team and run
21
+ * JavaScript from a dev server, so they never get the production restricted
22
+ * groups: they hold the `.dev` ones, and a production id may not name those.
23
+ *
24
+ * Every entry is NORMALISED before it is judged (`normalizeGroupName`): leading
25
+ * build variables (`$(AppIdentifierPrefix)`, `$(TeamIdentifierPrefix)`,
26
+ * `${…}`, nested), a leading ten-character team id and surrounding whitespace
27
+ * are stripped, and the name is compared without case. An entry that names a
28
+ * restricted group must then be spelled EXACTLY `$(AppIdentifierPrefix)<group>`
29
+ * (or `<TEAMID>.<group>` when checking built entitlements for that team), and
30
+ * an entry still carrying a build variable or a wildcard after normalisation
31
+ * cannot be judged and is refused.
32
+ *
17
33
  * Every other app keeps the shared group only. An app config that names a
18
34
  * restricted group without being its holder fails prebuild; the entitlement is
19
35
  * native, so this is the one place it can be stopped before it ships.
@@ -23,30 +39,75 @@ const PREFIX = '$(AppIdentifierPrefix)';
23
39
  const OXY_KEYCHAIN_GROUPS = Object.freeze({
24
40
  identity: 'so.oxy.identity',
25
41
  wallet: 'so.oxy.wallet',
42
+ identityDev: 'so.oxy.identity.dev',
43
+ walletDev: 'so.oxy.wallet.dev',
26
44
  shared: 'group.so.oxy.shared',
27
45
  });
28
46
 
29
- const COMMONS = ['so.oxy.commons', 'so.oxy.commons.dev'];
30
- const PEABLE_WALLET = ['to.peable.app', 'to.peable.app.dev'];
47
+ const G = OXY_KEYCHAIN_GROUPS;
31
48
 
32
49
  /** The exact leading entries each holder lists, by bundle id. */
33
50
  const HOLDER_LAYOUTS = Object.freeze({
34
- ...Object.fromEntries(
35
- COMMONS.map((id) => [
36
- id,
37
- [OXY_KEYCHAIN_GROUPS.identity, OXY_KEYCHAIN_GROUPS.wallet, OXY_KEYCHAIN_GROUPS.shared],
38
- ]),
39
- ),
40
- ...Object.fromEntries(
41
- PEABLE_WALLET.map((id) => [id, [OXY_KEYCHAIN_GROUPS.wallet, OXY_KEYCHAIN_GROUPS.shared]]),
42
- ),
51
+ 'so.oxy.commons': Object.freeze([G.identity, G.wallet, G.shared]),
52
+ 'so.oxy.commons.dev': Object.freeze([G.identityDev, G.walletDev, G.shared]),
53
+ 'to.peable.app': Object.freeze([G.wallet, G.shared]),
54
+ 'to.peable.app.dev': Object.freeze([G.walletDev, G.shared]),
43
55
  });
44
56
 
45
- const RESTRICTED = new Set([OXY_KEYCHAIN_GROUPS.identity, OXY_KEYCHAIN_GROUPS.wallet]);
57
+ /** Lower-cased restricted name → its canonical spelling. */
58
+ const RESTRICTED = new Map(
59
+ [G.identity, G.wallet, G.identityDev, G.walletDev].map((name) => [name.toLowerCase(), name]),
60
+ );
61
+
62
+ const TEAM_ID = /^[A-Z0-9]{10}$/;
63
+ const LEADING_TEAM_ID = /^[A-Z0-9]{10}\./i;
64
+
65
+ /**
66
+ * Length of the build variable (`$(…)` or `${…}`, nesting allowed) at the start
67
+ * of `text`, or 0 when it does not start with a complete one.
68
+ */
69
+ function leadingVariableLength(text) {
70
+ if (text[0] !== '$' || (text[1] !== '(' && text[1] !== '{')) return 0;
71
+ const stack = [];
72
+ for (let i = 1; i < text.length; i += 1) {
73
+ const ch = text[i];
74
+ if (ch === '(' || ch === '{') stack.push(ch === '(' ? ')' : '}');
75
+ else if (ch === ')' || ch === '}') {
76
+ if (stack.pop() !== ch) return 0;
77
+ if (stack.length === 0) return i + 1;
78
+ }
79
+ }
80
+ return 0;
81
+ }
82
+
83
+ /**
84
+ * The group an entry names, with every way of spelling its team prefix
85
+ * removed: `$(AppIdentifierPrefix)so.oxy.wallet`, `$(TeamIdentifierPrefix)
86
+ * so.oxy.wallet`, `ABCDE12345.so.oxy.wallet` → `so.oxy.wallet`. Case is kept;
87
+ * compare with `restrictedGroup`, which ignores it.
88
+ *
89
+ * @param {string} entry
90
+ */
91
+ function normalizeGroupName(entry) {
92
+ let rest = entry.trim();
93
+ for (;;) {
94
+ const variable = leadingVariableLength(rest);
95
+ if (variable > 0) {
96
+ rest = rest.slice(variable).trim();
97
+ continue;
98
+ }
99
+ const team = LEADING_TEAM_ID.exec(rest);
100
+ if (team) {
101
+ rest = rest.slice(team[0].length).trim();
102
+ continue;
103
+ }
104
+ return rest;
105
+ }
106
+ }
46
107
 
47
- /** `$(AppIdentifierPrefix)so.oxy.wallet` → `so.oxy.wallet`. */
48
- function groupName(entry) {
49
- return typeof entry === 'string' && entry.startsWith(PREFIX) ? entry.slice(PREFIX.length) : entry;
108
+ /** The canonical restricted group a normalised name is, in any case, or undefined. */
109
+ function restrictedGroup(name) {
110
+ return RESTRICTED.get(name.toLowerCase());
50
111
  }
51
112
 
52
113
  /** The entitlement entries for these group names, in order. */
@@ -59,38 +120,72 @@ function keychainEntries(groups) {
59
120
  * @param {string|undefined} bundleId
60
121
  */
61
122
  function keychainGroupsFor(bundleId) {
62
- return HOLDER_LAYOUTS[bundleId] ? [...HOLDER_LAYOUTS[bundleId]] : [OXY_KEYCHAIN_GROUPS.shared];
123
+ return Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '') ? [...HOLDER_LAYOUTS[bundleId]] : [G.shared];
124
+ }
125
+
126
+ function refuse(message) {
127
+ throw new Error(`[@oxy.so/app-preset] ${message} (docs/identity/ios-keychain-access-groups.md)`);
63
128
  }
64
129
 
65
130
  /**
66
131
  * Throw unless `entries` (a `keychain-access-groups` value) is one this bundle
67
- * id may ship: a restricted group only for its holders, and a holder's layout
68
- * as the leading entries, in order.
132
+ * id may ship: every entry judgeable, a restricted group only for its holders
133
+ * and only in its one spelling, and a holder's layout as the leading entries,
134
+ * in order.
69
135
  *
70
136
  * @param {string|undefined} bundleId
71
137
  * @param {unknown} entries
138
+ * @param {{ teamId?: string }} [options] `teamId`: the entries are BUILT
139
+ * (codesigned) entitlements of that team, so a restricted group is spelled
140
+ * `<teamId>.<group>` instead of `$(AppIdentifierPrefix)<group>`.
72
141
  */
73
- function assertOxyKeychainGroups(bundleId, entries) {
74
- if (!Array.isArray(entries)) return;
75
- const names = entries.map(groupName);
76
- const layout = HOLDER_LAYOUTS[bundleId];
77
- for (const name of names) {
78
- if (RESTRICTED.has(name) && !layout?.includes(name)) {
79
- throw new Error(
80
- `[@oxy.so/app-preset] ${bundleId ?? 'This app'} may not list the keychain access group "${name}": ` +
81
- 'only Commons holds the identity group and only Commons and the Peable wallet the wallet group ' +
82
- '(docs/identity/ios-keychain-access-groups.md). Every other Oxy app lists group.so.oxy.shared.',
142
+ function assertOxyKeychainGroups(bundleId, entries, options = {}) {
143
+ if (entries === undefined || entries === null) return;
144
+ const app = bundleId ?? 'This app';
145
+ if (!Array.isArray(entries)) {
146
+ refuse(`${app}: keychain-access-groups must be an array of strings`);
147
+ }
148
+ const { teamId } = options;
149
+ if (teamId !== undefined && !TEAM_ID.test(teamId)) {
150
+ refuse(`"${teamId}" is not an Apple team id (ten upper-case letters and digits)`);
151
+ }
152
+ const layout = Object.hasOwn(HOLDER_LAYOUTS, bundleId ?? '') ? HOLDER_LAYOUTS[bundleId] : [];
153
+
154
+ const names = entries.map((entry) => {
155
+ if (typeof entry !== 'string') {
156
+ refuse(`${app}: every keychain-access-groups entry must be a string`);
157
+ }
158
+ const name = normalizeGroupName(entry);
159
+ if (name === '' || /[$*?\s]/.test(name)) {
160
+ refuse(
161
+ `${app}: the keychain access group "${entry}" cannot be checked (a build variable, wildcard or ` +
162
+ 'whitespace past its team prefix). Name the group literally after $(AppIdentifierPrefix).',
83
163
  );
84
164
  }
85
- }
86
- const namesRestricted = names.some((name) => RESTRICTED.has(name));
87
- if (layout && namesRestricted) {
165
+ const restricted = restrictedGroup(name);
166
+ if (restricted === undefined) return name;
167
+ if (!layout.includes(restricted)) {
168
+ refuse(
169
+ `${app} may not list the keychain access group "${entry}" (${restricted}): only Commons holds ` +
170
+ 'the identity group and only Commons and the Peable wallet the wallet group, the production ' +
171
+ 'apps the production groups and their dev builds the .dev groups. Every other Oxy app lists ' +
172
+ 'group.so.oxy.shared',
173
+ );
174
+ }
175
+ const pinned = teamId === undefined ? `${PREFIX}${restricted}` : `${teamId}.${restricted}`;
176
+ if (entry !== pinned) {
177
+ refuse(`${app} must spell the keychain access group "${entry}" exactly "${pinned}"`);
178
+ }
179
+ return restricted;
180
+ });
181
+
182
+ if (layout.length > 0 && names.some((name) => restrictedGroup(name) !== undefined)) {
88
183
  const leading = names.slice(0, layout.length);
89
184
  if (leading.join(',') !== layout.join(',')) {
90
- throw new Error(
91
- `[@oxy.so/app-preset] ${bundleId} must list its keychain access groups as [${layout.join(', ')}] ` +
92
- `first, in that order (got [${names.join(', ')}]): the first entry is the default group, ` +
93
- 'which decides where the identity is written and what @oxy.so/core lets this app read.',
185
+ refuse(
186
+ `${bundleId} must list its keychain access groups as [${layout.join(', ')}] first, in that ` +
187
+ `order (got [${names.join(', ')}]): the first entry is the default group, which decides ` +
188
+ 'where the identity is written and what @oxy.so/core lets this app read',
94
189
  );
95
190
  }
96
191
  }
@@ -102,5 +197,6 @@ module.exports = {
102
197
  assertOxyKeychainGroups,
103
198
  keychainEntries,
104
199
  keychainGroupsFor,
105
- groupName,
200
+ normalizeGroupName,
201
+ restrictedGroup,
106
202
  };
@@ -60,6 +60,7 @@ function resolveBuildPropertiesPlugin(projectRoot) {
60
60
  "[@oxy.so/app-preset] withOxyBuildProperties requires the peer dependency 'expo-build-properties'. " +
61
61
  'Install it with `npx expo install expo-build-properties`, or disable it by passing ' +
62
62
  '`{ ios: false, android: false }` to the preset.',
63
+ { cause: error },
63
64
  );
64
65
  }
65
66
  const plugin = typeof mod === 'function' ? mod : mod.withBuildProperties || mod.default;
@@ -7,8 +7,10 @@
7
7
  * the shared group (`group.so.oxy.shared`: public keys and the device-session
8
8
  * credential), Commons `[so.oxy.identity, so.oxy.wallet, group.so.oxy.shared]`
9
9
  * and the Peable wallet `[so.oxy.wallet, group.so.oxy.shared]` — the first
10
- * entry is the default group, so it is part of the rule. The Android half is
11
- * Commons' identity host (`withOxySharedPermissions` in @oxy.so/services).
10
+ * entry is the default group, so it is part of the rule. Their dev builds
11
+ * (`.dev` bundle ids) get the `.dev` restricted groups instead. The Android
12
+ * half is Commons' identity host (`withOxySharedPermissions` in
13
+ * @oxy.so/services).
12
14
  *
13
15
  * The Oxy groups are put FIRST, in their order; entries the app or another
14
16
  * plugin already declared are kept after them. Then the policy is checked on
@@ -22,9 +24,10 @@
22
24
  const { withEntitlementsPlist } = require('expo/config-plugins');
23
25
  const {
24
26
  assertOxyKeychainGroups,
25
- groupName,
26
27
  keychainEntries,
27
28
  keychainGroupsFor,
29
+ normalizeGroupName,
30
+ restrictedGroup,
28
31
  } = require('./oxyKeychainGroups');
29
32
 
30
33
  const KEY = 'keychain-access-groups';
@@ -54,8 +57,15 @@ function withOxyKeychain(config, keychainGroups) {
54
57
 
55
58
  const next = withEntitlementsPlist(config, (config) => {
56
59
  const existing = Array.isArray(config.modResults[KEY]) ? config.modResults[KEY] : [];
57
- const wantedNames = new Set(wanted.map(groupName));
58
- const rest = existing.filter((entry) => !wantedNames.has(groupName(entry)));
60
+ // Drop what `wanted` already lists. Another spelling of a restricted group
61
+ // is KEPT, so the check below refuses it instead of quietly repairing it.
62
+ const wantedNames = new Set(wanted.map((entry) => normalizeGroupName(entry).toLowerCase()));
63
+ const rest = existing.filter((entry) => {
64
+ if (wanted.includes(entry)) return false;
65
+ if (typeof entry !== 'string') return true;
66
+ const name = normalizeGroupName(entry);
67
+ return restrictedGroup(name) !== undefined || !wantedNames.has(name.toLowerCase());
68
+ });
59
69
  const groups = [...wanted, ...rest];
60
70
  assertOxyKeychainGroups(bundleId, groups);
61
71
  config.modResults[KEY] = groups;