|
6 | 6 |
|
7 | 7 | import { suite, test } from "@testdeck/mocha";
|
8 | 8 | import * as chai from "chai";
|
9 |
| -import { SSHPublicKeyValue } from "."; |
| 9 | +import { SSHPublicKeyValue, EnvVar, EnvVarWithValue } from "."; |
10 | 10 |
|
11 | 11 | const expect = chai.expect;
|
12 | 12 |
|
@@ -94,4 +94,120 @@ class TestSSHPublicKeyValue {
|
94 | 94 | ).to.throw("Key is invalid");
|
95 | 95 | }
|
96 | 96 | }
|
97 |
| -module.exports = new TestSSHPublicKeyValue(); // Only to circumvent no usage warning :-/ |
| 97 | + |
| 98 | +@suite |
| 99 | +class TestEnvVar { |
| 100 | + @test |
| 101 | + public testGetGitpodImageAuth_empty() { |
| 102 | + const result = EnvVar.getGitpodImageAuth([]); |
| 103 | + expect(result.size).to.equal(0); |
| 104 | + } |
| 105 | + |
| 106 | + @test |
| 107 | + public testGetGitpodImageAuth_noRelevantVar() { |
| 108 | + const envVars: EnvVarWithValue[] = [{ name: "OTHER_VAR", value: "some_value" }]; |
| 109 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 110 | + expect(result.size).to.equal(0); |
| 111 | + } |
| 112 | + |
| 113 | + @test |
| 114 | + public testGetGitpodImageAuth_singleEntryNoPort() { |
| 115 | + const envVars: EnvVarWithValue[] = [ |
| 116 | + { |
| 117 | + name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME, |
| 118 | + value: "my-registry.foo.net:Zm9vOmJhcg==", |
| 119 | + }, |
| 120 | + ]; |
| 121 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 122 | + expect(result.size).to.equal(1); |
| 123 | + expect(result.get("my-registry.foo.net")).to.equal("Zm9vOmJhcg=="); |
| 124 | + } |
| 125 | + |
| 126 | + @test |
| 127 | + public testGetGitpodImageAuth_singleEntryWithPort() { |
| 128 | + const envVars: EnvVarWithValue[] = [ |
| 129 | + { |
| 130 | + name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME, |
| 131 | + value: "my-registry.foo.net:5000:Zm9vOmJhcg==", |
| 132 | + }, |
| 133 | + ]; |
| 134 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 135 | + expect(result.size).to.equal(1); |
| 136 | + expect(result.get("my-registry.foo.net:5000")).to.equal("Zm9vOmJhcg=="); |
| 137 | + } |
| 138 | + |
| 139 | + @test |
| 140 | + public testGetGitpodImageAuth_multipleEntries() { |
| 141 | + const envVars: EnvVarWithValue[] = [ |
| 142 | + { |
| 143 | + name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME, |
| 144 | + value: "my-registry.foo.net:Zm9vOmJhcg==,my-registry2.bar.com:YWJjOmRlZg==", |
| 145 | + }, |
| 146 | + ]; |
| 147 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 148 | + expect(result.size).to.equal(2); |
| 149 | + expect(result.get("my-registry.foo.net")).to.equal("Zm9vOmJhcg=="); |
| 150 | + expect(result.get("my-registry2.bar.com")).to.equal("YWJjOmRlZg=="); |
| 151 | + } |
| 152 | + |
| 153 | + @test |
| 154 | + public testGetGitpodImageAuth_multipleEntriesWithPortAndMalformed() { |
| 155 | + const envVars: EnvVarWithValue[] = [ |
| 156 | + { |
| 157 | + name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME, |
| 158 | + value: "my-registry.foo.net:5000:Zm9vOmJhcg==,my-registry2.bar.com:YWJjOmRlZg==,invalidEntry,another.host:anothercred", |
| 159 | + }, |
| 160 | + ]; |
| 161 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 162 | + expect(result.size).to.equal(3); |
| 163 | + expect(result.get("my-registry2.bar.com")).to.equal("YWJjOmRlZg=="); |
| 164 | + expect(result.get("another.host")).to.equal("anothercred"); |
| 165 | + expect(result.get("my-registry.foo.net:5000")).to.equal("Zm9vOmJhcg=="); |
| 166 | + } |
| 167 | + |
| 168 | + @test |
| 169 | + public testGetGitpodImageAuth_emptyValue() { |
| 170 | + const envVars: EnvVarWithValue[] = [ |
| 171 | + { |
| 172 | + name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME, |
| 173 | + value: "", |
| 174 | + }, |
| 175 | + ]; |
| 176 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 177 | + expect(result.size).to.equal(0); |
| 178 | + } |
| 179 | + |
| 180 | + @test |
| 181 | + public testGetGitpodImageAuth_malformedEntries() { |
| 182 | + const envVars: EnvVarWithValue[] = [ |
| 183 | + { |
| 184 | + name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME, |
| 185 | + value: "justhost,hostonly:,:credonly,:::,", |
| 186 | + }, |
| 187 | + ]; |
| 188 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 189 | + expect(result.size).to.equal(0); |
| 190 | + } |
| 191 | + |
| 192 | + @test |
| 193 | + public testGetGitpodImageAuth_entriesWithSpaces() { |
| 194 | + const envVars: EnvVarWithValue[] = [ |
| 195 | + { |
| 196 | + name: EnvVar.GITPOD_IMAGE_AUTH_ENV_VAR_NAME, |
| 197 | + value: " my-registry.foo.net : Zm9vOmJhcg== , my-registry2.bar.com:YWJjOmRlZg== ", |
| 198 | + }, |
| 199 | + ]; |
| 200 | + const result = EnvVar.getGitpodImageAuth(envVars); |
| 201 | + expect(result.size).to.equal(2); |
| 202 | + expect(result.get("my-registry.foo.net ")).to.equal(" Zm9vOmJhcg=="); |
| 203 | + expect(result.get("my-registry2.bar.com")).to.equal("YWJjOmRlZg=="); |
| 204 | + } |
| 205 | +} |
| 206 | + |
| 207 | +// Exporting both test suites |
| 208 | +const testSSHPublicKeyValue = new TestSSHPublicKeyValue(); |
| 209 | +const testEnvVar = new TestEnvVar(); |
| 210 | +module.exports = { |
| 211 | + testSSHPublicKeyValue, |
| 212 | + testEnvVar, |
| 213 | +}; |
0 commit comments