|
1 | 1 | package org.rundeck.client.tool.commands.projects |
2 | 2 |
|
3 | | -import groovy.transform.CompileStatic |
4 | | -import okhttp3.ResponseBody |
| 3 | + |
5 | 4 | import org.rundeck.client.api.RundeckApi |
6 | 5 | import org.rundeck.client.api.model.AsyncProjectImportStatus |
7 | 6 | import org.rundeck.client.api.model.ProjectImportStatus |
8 | 7 | import org.rundeck.client.tool.CommandOutput |
| 8 | +import org.rundeck.client.tool.InputError |
9 | 9 | import org.rundeck.client.tool.RdApp |
10 | 10 | import org.rundeck.client.tool.commands.RdToolImpl |
11 | 11 | import org.rundeck.client.tool.options.ProjectNameOptions |
12 | | -import org.rundeck.client.tool.options.ProjectRequiredNameOptions |
13 | 12 | import org.rundeck.client.util.Client |
14 | 13 | import org.rundeck.client.util.RdClientConfig |
15 | | -import retrofit2.Response |
16 | 14 | import retrofit2.Retrofit |
17 | 15 | import retrofit2.converter.jackson.JacksonConverterFactory |
18 | 16 | import retrofit2.mock.Calls |
@@ -82,6 +80,310 @@ class ArchivesSpec extends Specification { |
82 | 80 | 0 * api._(*_) |
83 | 81 | result == 0 |
84 | 82 | } |
| 83 | + |
| 84 | + def "api version < 34 fails for webhooks or webhook regen auth flag"() { |
| 85 | + |
| 86 | + def api = Mock(RundeckApi) |
| 87 | + |
| 88 | + def retrofit = new Retrofit.Builder() |
| 89 | + .addConverterFactory(JacksonConverterFactory.create()) |
| 90 | + .baseUrl('http://example.com/fake/').build() |
| 91 | + def out = Mock(CommandOutput) |
| 92 | + def client = new Client(api, retrofit, null, null, apiversion, true, null) |
| 93 | + |
| 94 | + def rdapp = Mock(RdApp) { |
| 95 | + getClient() >> client |
| 96 | + getAppConfig() >> Mock(RdClientConfig) |
| 97 | + } |
| 98 | + def rdTool = new RdToolImpl(rdapp) |
| 99 | + |
| 100 | + def sut = new Archives() |
| 101 | + sut.rdOutput = out |
| 102 | + sut.rdTool = rdTool |
| 103 | + def opts = new Archives.ArchiveImportOpts() |
| 104 | + opts.components = ['test-comp'].toSet() |
| 105 | + opts.componentOptions = ['test-comp.key': 'value'] |
| 106 | + opts.file = tempFile |
| 107 | + opts.project = 'Aproj' |
| 108 | + if (useIncludeFlags) { |
| 109 | + opts.setIncludeFlags(new HashSet<Archives.ImportFlags>([Archives.ImportFlags.webhooks])) |
| 110 | + } else { |
| 111 | + opts.includeWebhooks = true |
| 112 | + } |
| 113 | + opts.whkRegenAuthTokens = true |
| 114 | + |
| 115 | + |
| 116 | + when: |
| 117 | + def result = sut.importArchive(opts) |
| 118 | + |
| 119 | + then: |
| 120 | + InputError exc = thrown() |
| 121 | + exc.message.contains('Cannot use --include-webhooks or --regenerate-tokens with API < 34') |
| 122 | + |
| 123 | + where: |
| 124 | + apiversion = 33 |
| 125 | + useIncludeFlags << [true, false] |
| 126 | + } |
| 127 | + |
| 128 | + def "api version 34 ok for webhooks or webhook regen auth flag"() { |
| 129 | + |
| 130 | + def api = Mock(RundeckApi) |
| 131 | + |
| 132 | + def retrofit = new Retrofit.Builder() |
| 133 | + .addConverterFactory(JacksonConverterFactory.create()) |
| 134 | + .baseUrl('http://example.com/fake/').build() |
| 135 | + def out = Mock(CommandOutput) |
| 136 | + def client = new Client(api, retrofit, null, null, 34, true, null) |
| 137 | + |
| 138 | + def rdapp = Mock(RdApp) { |
| 139 | + getClient() >> client |
| 140 | + getAppConfig() >> Mock(RdClientConfig) |
| 141 | + } |
| 142 | + def rdTool = new RdToolImpl(rdapp) |
| 143 | + |
| 144 | + def sut = new Archives() |
| 145 | + sut.rdOutput = out |
| 146 | + sut.rdTool = rdTool |
| 147 | + def opts = new Archives.ArchiveImportOpts() |
| 148 | + opts.components = ['test-comp'].toSet() |
| 149 | + opts.componentOptions = ['test-comp.key': 'value'] |
| 150 | + opts.file = tempFile |
| 151 | + opts.project = 'Aproj' |
| 152 | + |
| 153 | + if (useIncludeFlags) { |
| 154 | + opts.setIncludeFlags(new HashSet<Archives.ImportFlags>([Archives.ImportFlags.webhooks])) |
| 155 | + } else { |
| 156 | + opts.includeWebhooks = true |
| 157 | + } |
| 158 | + opts.whkRegenAuthTokens = true |
| 159 | + |
| 160 | + |
| 161 | + when: |
| 162 | + def result = sut.importArchive(opts) |
| 163 | + |
| 164 | + then: |
| 165 | + 1 * api.importProjectArchive( |
| 166 | + 'Aproj', |
| 167 | + _, |
| 168 | + _, |
| 169 | + _, |
| 170 | + _, |
| 171 | + _, |
| 172 | + true, |
| 173 | + true, |
| 174 | + _, |
| 175 | + _, |
| 176 | + _, |
| 177 | + _, |
| 178 | + _ |
| 179 | + ) >> Calls.response(new ProjectImportStatus(successful: true)) |
| 180 | + 0 * api._(*_) |
| 181 | + result == 0 |
| 182 | + where: |
| 183 | + useIncludeFlags << [true, false] |
| 184 | + } |
| 185 | + |
| 186 | + def "api version < 38 fails for node sources flag"() { |
| 187 | + |
| 188 | + def api = Mock(RundeckApi) |
| 189 | + |
| 190 | + def retrofit = new Retrofit.Builder() |
| 191 | + .addConverterFactory(JacksonConverterFactory.create()) |
| 192 | + .baseUrl('http://example.com/fake/').build() |
| 193 | + def out = Mock(CommandOutput) |
| 194 | + def client = new Client(api, retrofit, null, null, apiversion, true, null) |
| 195 | + |
| 196 | + def rdapp = Mock(RdApp) { |
| 197 | + getClient() >> client |
| 198 | + getAppConfig() >> Mock(RdClientConfig) |
| 199 | + } |
| 200 | + def rdTool = new RdToolImpl(rdapp) |
| 201 | + |
| 202 | + def sut = new Archives() |
| 203 | + sut.rdOutput = out |
| 204 | + sut.rdTool = rdTool |
| 205 | + def opts = new Archives.ArchiveImportOpts() |
| 206 | + opts.components = ['test-comp'].toSet() |
| 207 | + opts.componentOptions = ['test-comp.key': 'value'] |
| 208 | + opts.file = tempFile |
| 209 | + opts.project = 'Aproj' |
| 210 | + |
| 211 | + if (useIncludeFlags) { |
| 212 | + opts.setIncludeFlags(new HashSet<Archives.ImportFlags>([Archives.ImportFlags.nodeSources])) |
| 213 | + } else { |
| 214 | + opts.includeNodeSources = true |
| 215 | + } |
| 216 | + |
| 217 | + |
| 218 | + when: |
| 219 | + def result = sut.importArchive(opts) |
| 220 | + |
| 221 | + then: |
| 222 | + InputError exc = thrown() |
| 223 | + exc.message.contains('Cannot use --include-node-sources with API < 38') |
| 224 | + |
| 225 | + where: |
| 226 | + apiversion = 37 |
| 227 | + useIncludeFlags << [true, false] |
| 228 | + } |
| 229 | + |
| 230 | + def "api version 38 ok for node sources flag"() { |
| 231 | + |
| 232 | + def api = Mock(RundeckApi) |
| 233 | + |
| 234 | + def retrofit = new Retrofit.Builder() |
| 235 | + .addConverterFactory(JacksonConverterFactory.create()) |
| 236 | + .baseUrl('http://example.com/fake/').build() |
| 237 | + def out = Mock(CommandOutput) |
| 238 | + def client = new Client(api, retrofit, null, null, 38, true, null) |
| 239 | + |
| 240 | + def rdapp = Mock(RdApp) { |
| 241 | + getClient() >> client |
| 242 | + getAppConfig() >> Mock(RdClientConfig) |
| 243 | + } |
| 244 | + def rdTool = new RdToolImpl(rdapp) |
| 245 | + |
| 246 | + def sut = new Archives() |
| 247 | + sut.rdOutput = out |
| 248 | + sut.rdTool = rdTool |
| 249 | + def opts = new Archives.ArchiveImportOpts() |
| 250 | + opts.components = ['test-comp'].toSet() |
| 251 | + opts.componentOptions = ['test-comp.key': 'value'] |
| 252 | + opts.file = tempFile |
| 253 | + opts.project = 'Aproj' |
| 254 | + |
| 255 | + if (useIncludeFlags) { |
| 256 | + opts.setIncludeFlags(new HashSet<Archives.ImportFlags>([Archives.ImportFlags.nodeSources])) |
| 257 | + } else { |
| 258 | + opts.includeNodeSources = true |
| 259 | + } |
| 260 | + |
| 261 | + when: |
| 262 | + def result = sut.importArchive(opts) |
| 263 | + |
| 264 | + then: |
| 265 | + 1 * api.importProjectArchive( |
| 266 | + 'Aproj', |
| 267 | + _, |
| 268 | + _, |
| 269 | + _, |
| 270 | + _, |
| 271 | + _, |
| 272 | + false, |
| 273 | + false, |
| 274 | + _, |
| 275 | + true, |
| 276 | + _, |
| 277 | + _, |
| 278 | + _ |
| 279 | + ) >> Calls.response(new ProjectImportStatus(successful: true)) |
| 280 | + 0 * api._(*_) |
| 281 | + result == 0 |
| 282 | + where: |
| 283 | + useIncludeFlags << [true, false] |
| 284 | + } |
| 285 | + def "api version < 47 fails for webhook regen uuids"() { |
| 286 | + |
| 287 | + def api = Mock(RundeckApi) |
| 288 | + |
| 289 | + def retrofit = new Retrofit.Builder() |
| 290 | + .addConverterFactory(JacksonConverterFactory.create()) |
| 291 | + .baseUrl('http://example.com/fake/').build() |
| 292 | + def out = Mock(CommandOutput) |
| 293 | + def client = new Client(api, retrofit, null, null, apiversion, true, null) |
| 294 | + |
| 295 | + def rdapp = Mock(RdApp) { |
| 296 | + getClient() >> client |
| 297 | + getAppConfig() >> Mock(RdClientConfig) |
| 298 | + } |
| 299 | + def rdTool = new RdToolImpl(rdapp) |
| 300 | + |
| 301 | + def sut = new Archives() |
| 302 | + sut.rdOutput = out |
| 303 | + sut.rdTool = rdTool |
| 304 | + def opts = new Archives.ArchiveImportOpts() |
| 305 | + opts.components = ['test-comp'].toSet() |
| 306 | + opts.componentOptions = ['test-comp.key': 'value'] |
| 307 | + opts.file = tempFile |
| 308 | + opts.project = 'Aproj' |
| 309 | + |
| 310 | + if (useIncludeFlags) { |
| 311 | + opts.setIncludeFlags(new HashSet<Archives.ImportFlags>([Archives.ImportFlags.webhooks])) |
| 312 | + } else { |
| 313 | + opts.includeWebhooks = true |
| 314 | + } |
| 315 | + opts.whkRegenUuid=true |
| 316 | + |
| 317 | + |
| 318 | + when: |
| 319 | + def result = sut.importArchive(opts) |
| 320 | + |
| 321 | + then: |
| 322 | + InputError exc = thrown() |
| 323 | + exc.message.contains('Cannot use --include-webhooks with --remove-webhooks-uuids with API < 47') |
| 324 | + |
| 325 | + where: |
| 326 | + apiversion = 46 |
| 327 | + useIncludeFlags << [true, false] |
| 328 | + } |
| 329 | + |
| 330 | + def "api version 47 ok for webhook regen uuids flag"() { |
| 331 | + |
| 332 | + def api = Mock(RundeckApi) |
| 333 | + |
| 334 | + def retrofit = new Retrofit.Builder() |
| 335 | + .addConverterFactory(JacksonConverterFactory.create()) |
| 336 | + .baseUrl('http://example.com/fake/').build() |
| 337 | + def out = Mock(CommandOutput) |
| 338 | + def client = new Client(api, retrofit, null, null, 47, true, null) |
| 339 | + |
| 340 | + def rdapp = Mock(RdApp) { |
| 341 | + getClient() >> client |
| 342 | + getAppConfig() >> Mock(RdClientConfig) |
| 343 | + } |
| 344 | + def rdTool = new RdToolImpl(rdapp) |
| 345 | + |
| 346 | + def sut = new Archives() |
| 347 | + sut.rdOutput = out |
| 348 | + sut.rdTool = rdTool |
| 349 | + def opts = new Archives.ArchiveImportOpts() |
| 350 | + opts.components = ['test-comp'].toSet() |
| 351 | + opts.componentOptions = ['test-comp.key': 'value'] |
| 352 | + opts.file = tempFile |
| 353 | + opts.project = 'Aproj' |
| 354 | + |
| 355 | + if (useIncludeFlags) { |
| 356 | + opts.setIncludeFlags(new HashSet<Archives.ImportFlags>([Archives.ImportFlags.webhooks])) |
| 357 | + } else { |
| 358 | + opts.includeWebhooks = true |
| 359 | + } |
| 360 | + opts.whkRegenUuid=true |
| 361 | + |
| 362 | + when: |
| 363 | + def result = sut.importArchive(opts) |
| 364 | + |
| 365 | + then: |
| 366 | + 1 * api.importProjectArchive( |
| 367 | + 'Aproj', |
| 368 | + _, |
| 369 | + _, |
| 370 | + _, |
| 371 | + _, |
| 372 | + _, |
| 373 | + true, |
| 374 | + _, |
| 375 | + true, |
| 376 | + _, |
| 377 | + _, |
| 378 | + _, |
| 379 | + _ |
| 380 | + ) >> Calls.response(new ProjectImportStatus(successful: true)) |
| 381 | + 0 * api._(*_) |
| 382 | + result == 0 |
| 383 | + where: |
| 384 | + useIncludeFlags << [true, false] |
| 385 | + } |
| 386 | + |
85 | 387 | def "import include via direct flags"() { |
86 | 388 |
|
87 | 389 | def api = Mock(RundeckApi) |
|
0 commit comments