|
| 1 | +package io.sdkman.broker.acceptance |
| 2 | + |
| 3 | +import io.kotest.core.spec.style.ShouldSpec |
| 4 | +import io.kotest.matchers.shouldBe |
| 5 | +import io.ktor.client.request.get |
| 6 | +import io.ktor.http.HttpHeaders |
| 7 | +import io.ktor.http.HttpStatusCode |
| 8 | +import io.ktor.server.testing.testApplication |
| 9 | +import io.sdkman.broker.support.configureAppForTesting |
| 10 | +import org.junit.jupiter.api.Tag |
| 11 | + |
| 12 | +@Tag("acceptance") |
| 13 | +class SdkmanCliDownloadAcceptanceSpec : ShouldSpec({ |
| 14 | + |
| 15 | + context("SDKMAN CLI download endpoint") { |
| 16 | + should("redirect to GitHub release for stable version with install command") { |
| 17 | + testApplication { |
| 18 | + application { |
| 19 | + configureAppForTesting() |
| 20 | + } |
| 21 | + |
| 22 | + val client = |
| 23 | + createClient { |
| 24 | + followRedirects = false |
| 25 | + } |
| 26 | + |
| 27 | + // when: client requests SDKMAN CLI stable version |
| 28 | + val response = client.get("/download/sdkman/install/5.19.0/linuxx64") |
| 29 | + |
| 30 | + // then: should redirect to GitHub release |
| 31 | + response.status shouldBe HttpStatusCode.Found |
| 32 | + response.headers[HttpHeaders.Location] shouldBe |
| 33 | + "https://github.com/sdkman/sdkman-cli/releases/download/5.19.0/sdkman-cli-5.19.0.zip" |
| 34 | + response.headers["X-Sdkman-ArchiveType"] shouldBe "zip" |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + should("redirect to GitHub release for stable version with selfupdate command") { |
| 39 | + testApplication { |
| 40 | + application { |
| 41 | + configureAppForTesting() |
| 42 | + } |
| 43 | + |
| 44 | + val client = |
| 45 | + createClient { |
| 46 | + followRedirects = false |
| 47 | + } |
| 48 | + |
| 49 | + // when: client requests SDKMAN CLI stable version with selfupdate |
| 50 | + val response = client.get("/download/sdkman/selfupdate/5.19.0/darwinarm64") |
| 51 | + |
| 52 | + // then: should redirect to GitHub release |
| 53 | + response.status shouldBe HttpStatusCode.Found |
| 54 | + response.headers[HttpHeaders.Location] shouldBe |
| 55 | + "https://github.com/sdkman/sdkman-cli/releases/download/5.19.0/sdkman-cli-5.19.0.zip" |
| 56 | + response.headers["X-Sdkman-ArchiveType"] shouldBe "zip" |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + should("redirect to GitHub release for beta version with latest+ prefix") { |
| 61 | + testApplication { |
| 62 | + application { |
| 63 | + configureAppForTesting() |
| 64 | + } |
| 65 | + |
| 66 | + val client = |
| 67 | + createClient { |
| 68 | + followRedirects = false |
| 69 | + } |
| 70 | + |
| 71 | + // when: client requests SDKMAN CLI beta version |
| 72 | + val response = client.get("/download/sdkman/install/latest+b8d230b/linuxx64") |
| 73 | + |
| 74 | + // then: should redirect to GitHub release with latest tag |
| 75 | + response.status shouldBe HttpStatusCode.Found |
| 76 | + response.headers[HttpHeaders.Location] shouldBe |
| 77 | + "https://github.com/sdkman/sdkman-cli/releases/download/latest/sdkman-cli-latest+b8d230b.zip" |
| 78 | + response.headers["X-Sdkman-ArchiveType"] shouldBe "zip" |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + should("return 400 Bad Request for invalid command") { |
| 83 | + testApplication { |
| 84 | + application { |
| 85 | + configureAppForTesting() |
| 86 | + } |
| 87 | + |
| 88 | + val client = |
| 89 | + createClient { |
| 90 | + followRedirects = false |
| 91 | + } |
| 92 | + |
| 93 | + // when: client requests with invalid command |
| 94 | + val response = client.get("/download/sdkman/invalid/5.19.0/linuxx64") |
| 95 | + |
| 96 | + // then: should return bad request |
| 97 | + response.status shouldBe HttpStatusCode.BadRequest |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + should("return 400 Bad Request for empty version") { |
| 102 | + testApplication { |
| 103 | + application { |
| 104 | + configureAppForTesting() |
| 105 | + } |
| 106 | + |
| 107 | + val client = |
| 108 | + createClient { |
| 109 | + followRedirects = false |
| 110 | + } |
| 111 | + |
| 112 | + // when: client requests with blank version (space) |
| 113 | + val response = client.get("/download/sdkman/install/%20/linuxx64") |
| 114 | + |
| 115 | + // then: should return bad request |
| 116 | + response.status shouldBe HttpStatusCode.BadRequest |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + should("return 400 Bad Request for invalid platform") { |
| 121 | + testApplication { |
| 122 | + application { |
| 123 | + configureAppForTesting() |
| 124 | + } |
| 125 | + |
| 126 | + val client = |
| 127 | + createClient { |
| 128 | + followRedirects = false |
| 129 | + } |
| 130 | + |
| 131 | + // when: client requests with invalid platform |
| 132 | + val response = client.get("/download/sdkman/install/5.19.0/invalidplatform") |
| 133 | + |
| 134 | + // then: should return bad request |
| 135 | + response.status shouldBe HttpStatusCode.BadRequest |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + should("work with different valid platforms (platform validation only)") { |
| 140 | + testApplication { |
| 141 | + application { |
| 142 | + configureAppForTesting() |
| 143 | + } |
| 144 | + |
| 145 | + val client = |
| 146 | + createClient { |
| 147 | + followRedirects = false |
| 148 | + } |
| 149 | + |
| 150 | + // when: client requests with different valid platforms |
| 151 | + val platforms = listOf("linuxx64", "linuxarm64", "darwinx64", "darwinarm64", "windowsx64") |
| 152 | + |
| 153 | + platforms.forEach { platform -> |
| 154 | + val response = client.get("/download/sdkman/install/5.19.0/$platform") |
| 155 | + |
| 156 | + // then: should redirect successfully for all valid platforms |
| 157 | + response.status shouldBe HttpStatusCode.Found |
| 158 | + response.headers[HttpHeaders.Location] shouldBe |
| 159 | + "https://github.com/sdkman/sdkman-cli/releases/download/5.19.0/sdkman-cli-5.19.0.zip" |
| 160 | + response.headers["X-Sdkman-ArchiveType"] shouldBe "zip" |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + should("handle case sensitivity correctly for commands") { |
| 166 | + testApplication { |
| 167 | + application { |
| 168 | + configureAppForTesting() |
| 169 | + } |
| 170 | + |
| 171 | + val client = |
| 172 | + createClient { |
| 173 | + followRedirects = false |
| 174 | + } |
| 175 | + |
| 176 | + // when: client requests with uppercase command |
| 177 | + val response = client.get("/download/sdkman/INSTALL/5.19.0/linuxx64") |
| 178 | + |
| 179 | + // then: should return bad request (case sensitive) |
| 180 | + response.status shouldBe HttpStatusCode.BadRequest |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + should("verify that platform parameter is validated but not used in URL construction") { |
| 185 | + testApplication { |
| 186 | + application { |
| 187 | + configureAppForTesting() |
| 188 | + } |
| 189 | + |
| 190 | + val client = |
| 191 | + createClient { |
| 192 | + followRedirects = false |
| 193 | + } |
| 194 | + |
| 195 | + // when: client requests with different valid platforms |
| 196 | + val response1 = client.get("/download/sdkman/install/5.19.0/linuxx64") |
| 197 | + val response2 = client.get("/download/sdkman/install/5.19.0/windowsx64") |
| 198 | + |
| 199 | + // then: both should redirect to same URL (platform-agnostic) |
| 200 | + response1.status shouldBe HttpStatusCode.Found |
| 201 | + response2.status shouldBe HttpStatusCode.Found |
| 202 | + response1.headers[HttpHeaders.Location] shouldBe response2.headers[HttpHeaders.Location] |
| 203 | + } |
| 204 | + } |
| 205 | + } |
| 206 | +}) |
0 commit comments