|
| 1 | +import { getConfig } from '@expo/config'; |
| 2 | +import { vol } from 'memfs'; |
| 3 | + |
| 4 | +import * as prompts from '../../../prompts'; |
| 5 | +import { ensureNonExemptEncryptionIsDefinedForManagedProjectAsync } from '../exemptEncryption'; |
| 6 | + |
| 7 | +jest.mock('fs'); |
| 8 | +jest.mock('../../../prompts'); |
| 9 | + |
| 10 | +beforeEach(async () => { |
| 11 | + jest.resetAllMocks(); |
| 12 | + vol.reset(); |
| 13 | +}); |
| 14 | + |
| 15 | +test('prompts non-exempt encryption is not used', async () => { |
| 16 | + const projectRoot = '/project'; |
| 17 | + vol.fromJSON( |
| 18 | + { |
| 19 | + 'package.json': JSON.stringify({}), |
| 20 | + 'app.json': JSON.stringify({ |
| 21 | + expo: { |
| 22 | + name: 'myproject', |
| 23 | + slug: 'myproject', |
| 24 | + }, |
| 25 | + }), |
| 26 | + }, |
| 27 | + projectRoot |
| 28 | + ); |
| 29 | + |
| 30 | + jest.mocked(prompts.confirmAsync).mockReset().mockResolvedValueOnce(true); |
| 31 | + |
| 32 | + await ensureNonExemptEncryptionIsDefinedForManagedProjectAsync({ |
| 33 | + projectDir: projectRoot, |
| 34 | + exp: getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp, |
| 35 | + nonInteractive: false, |
| 36 | + }); |
| 37 | + |
| 38 | + expect(getConfig(projectRoot, { skipSDKVersionRequirement: true }).rootConfig).toEqual({ |
| 39 | + expo: { |
| 40 | + ios: { |
| 41 | + infoPlist: { |
| 42 | + ITSAppUsesNonExemptEncryption: false, |
| 43 | + }, |
| 44 | + }, |
| 45 | + name: 'myproject', |
| 46 | + slug: 'myproject', |
| 47 | + }, |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +test('does not prompt if the value is already set', async () => { |
| 52 | + const projectRoot = '/project'; |
| 53 | + vol.fromJSON( |
| 54 | + { |
| 55 | + 'package.json': JSON.stringify({}), |
| 56 | + 'app.json': JSON.stringify({ |
| 57 | + name: 'myproject', |
| 58 | + slug: 'myproject', |
| 59 | + ios: { |
| 60 | + infoPlist: { |
| 61 | + ITSAppUsesNonExemptEncryption: false, |
| 62 | + }, |
| 63 | + }, |
| 64 | + }), |
| 65 | + }, |
| 66 | + projectRoot |
| 67 | + ); |
| 68 | + |
| 69 | + // Reset but no mock values. |
| 70 | + jest.mocked(prompts.confirmAsync).mockReset(); |
| 71 | + |
| 72 | + await ensureNonExemptEncryptionIsDefinedForManagedProjectAsync({ |
| 73 | + projectDir: projectRoot, |
| 74 | + exp: getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp, |
| 75 | + nonInteractive: false, |
| 76 | + }); |
| 77 | + |
| 78 | + expect(prompts.confirmAsync).toHaveBeenCalledTimes(0); |
| 79 | + |
| 80 | + expect(getConfig(projectRoot, { skipSDKVersionRequirement: true }).rootConfig).toEqual({ |
| 81 | + ios: { |
| 82 | + infoPlist: { |
| 83 | + ITSAppUsesNonExemptEncryption: false, |
| 84 | + }, |
| 85 | + }, |
| 86 | + name: 'myproject', |
| 87 | + slug: 'myproject', |
| 88 | + }); |
| 89 | +}); |
| 90 | + |
| 91 | +test('prompts non-exempt encryption in CI', async () => { |
| 92 | + const projectRoot = '/project'; |
| 93 | + vol.fromJSON( |
| 94 | + { |
| 95 | + 'package.json': JSON.stringify({}), |
| 96 | + 'app.json': JSON.stringify({ |
| 97 | + expo: { |
| 98 | + name: 'myproject', |
| 99 | + slug: 'myproject', |
| 100 | + }, |
| 101 | + }), |
| 102 | + }, |
| 103 | + projectRoot |
| 104 | + ); |
| 105 | + |
| 106 | + // Reset but no mock values. |
| 107 | + jest.mocked(prompts.confirmAsync).mockReset(); |
| 108 | + |
| 109 | + await ensureNonExemptEncryptionIsDefinedForManagedProjectAsync({ |
| 110 | + projectDir: projectRoot, |
| 111 | + exp: getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp, |
| 112 | + nonInteractive: false, |
| 113 | + }); |
| 114 | + |
| 115 | + expect(getConfig(projectRoot, { skipSDKVersionRequirement: true }).rootConfig).toEqual({ |
| 116 | + expo: { |
| 117 | + ios: { |
| 118 | + infoPlist: { |
| 119 | + ITSAppUsesNonExemptEncryption: false, |
| 120 | + }, |
| 121 | + }, |
| 122 | + name: 'myproject', |
| 123 | + slug: 'myproject', |
| 124 | + }, |
| 125 | + }); |
| 126 | +}); |
| 127 | + |
| 128 | +test('prompts non-exempt encryption is not used but app.config.js', async () => { |
| 129 | + const projectRoot = '/project'; |
| 130 | + vol.fromJSON( |
| 131 | + { |
| 132 | + 'package.json': JSON.stringify({}), |
| 133 | + 'app.config.js': |
| 134 | + `module.exports = ` + |
| 135 | + JSON.stringify({ |
| 136 | + expo: { |
| 137 | + name: 'myproject', |
| 138 | + slug: 'myproject', |
| 139 | + }, |
| 140 | + }), |
| 141 | + }, |
| 142 | + projectRoot |
| 143 | + ); |
| 144 | + |
| 145 | + jest.mocked(prompts.confirmAsync).mockReset().mockResolvedValueOnce(true); |
| 146 | + |
| 147 | + await ensureNonExemptEncryptionIsDefinedForManagedProjectAsync({ |
| 148 | + projectDir: projectRoot, |
| 149 | + exp: getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp, |
| 150 | + nonInteractive: false, |
| 151 | + }); |
| 152 | + |
| 153 | + // Not set. |
| 154 | + expect(getConfig(projectRoot, { skipSDKVersionRequirement: true }).rootConfig).toEqual({}); |
| 155 | +}); |
| 156 | + |
| 157 | +test('prompts non-exempt encryption is used', async () => { |
| 158 | + const projectRoot = '/project'; |
| 159 | + vol.fromJSON( |
| 160 | + { |
| 161 | + 'package.json': JSON.stringify({}), |
| 162 | + 'app.json': JSON.stringify({ |
| 163 | + expo: { |
| 164 | + name: 'myproject', |
| 165 | + slug: 'myproject', |
| 166 | + }, |
| 167 | + }), |
| 168 | + }, |
| 169 | + projectRoot |
| 170 | + ); |
| 171 | + |
| 172 | + jest |
| 173 | + .mocked(prompts.confirmAsync) |
| 174 | + .mockReset() |
| 175 | + .mockResolvedValueOnce(false) |
| 176 | + // Are you sure? |
| 177 | + .mockResolvedValueOnce(true); |
| 178 | + |
| 179 | + await ensureNonExemptEncryptionIsDefinedForManagedProjectAsync({ |
| 180 | + projectDir: projectRoot, |
| 181 | + exp: getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp, |
| 182 | + nonInteractive: false, |
| 183 | + }); |
| 184 | + |
| 185 | + expect(prompts.confirmAsync).toHaveBeenCalledTimes(2); |
| 186 | + |
| 187 | + expect(getConfig(projectRoot, { skipSDKVersionRequirement: true }).rootConfig).toEqual({ |
| 188 | + expo: { |
| 189 | + name: 'myproject', |
| 190 | + slug: 'myproject', |
| 191 | + }, |
| 192 | + }); |
| 193 | +}); |
| 194 | + |
| 195 | +test('prompts non-exempt encryption is used but backed out', async () => { |
| 196 | + const projectRoot = '/project'; |
| 197 | + vol.fromJSON( |
| 198 | + { |
| 199 | + 'package.json': JSON.stringify({}), |
| 200 | + 'app.json': JSON.stringify({ |
| 201 | + expo: { |
| 202 | + name: 'myproject', |
| 203 | + slug: 'myproject', |
| 204 | + }, |
| 205 | + }), |
| 206 | + }, |
| 207 | + projectRoot |
| 208 | + ); |
| 209 | + |
| 210 | + jest |
| 211 | + .mocked(prompts.confirmAsync) |
| 212 | + .mockReset() |
| 213 | + .mockResolvedValueOnce(false) |
| 214 | + // Are you sure? |
| 215 | + .mockResolvedValueOnce(false); |
| 216 | + |
| 217 | + await ensureNonExemptEncryptionIsDefinedForManagedProjectAsync({ |
| 218 | + projectDir: projectRoot, |
| 219 | + exp: getConfig(projectRoot, { skipSDKVersionRequirement: true }).exp, |
| 220 | + nonInteractive: false, |
| 221 | + }); |
| 222 | + |
| 223 | + expect(getConfig(projectRoot, { skipSDKVersionRequirement: true }).rootConfig).toEqual({ |
| 224 | + expo: { |
| 225 | + name: 'myproject', |
| 226 | + slug: 'myproject', |
| 227 | + ios: { |
| 228 | + infoPlist: { |
| 229 | + ITSAppUsesNonExemptEncryption: false, |
| 230 | + }, |
| 231 | + }, |
| 232 | + }, |
| 233 | + }); |
| 234 | +}); |
0 commit comments