Skip to content

Commit fb8ac9a

Browse files
committed
Prevent the use command from accessing the internet.
1 parent ece7ad0 commit fb8ac9a

File tree

4 files changed

+10
-49
lines changed

4 files changed

+10
-49
lines changed

src/main/bash/sdkman-use.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,32 @@ function __sdk_use() {
2323
version="$2"
2424
__sdkman_check_version_present "$version" || return 1
2525
__sdkman_check_candidate_present "$candidate" || return 1
26-
__sdkman_determine_version "$candidate" "$version" || return 1
2726

28-
if [[ ! -d "${SDKMAN_CANDIDATES_DIR}/${candidate}/${VERSION}" ]]; then
27+
if [[ ! -d "${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}" ]]; then
2928
echo ""
30-
__sdkman_echo_red "Stop! ${candidate} ${VERSION} is not installed."
29+
__sdkman_echo_red "Stop! ${candidate} ${version} is not installed."
3130
return 1
3231
fi
3332

3433
# Just update the *_HOME and PATH for this shell.
35-
__sdkman_set_candidate_home "$candidate" "$VERSION"
34+
__sdkman_set_candidate_home "$candidate" "$version"
3635

3736
# Replace the current path for the candidate with the selected version.
3837
if [[ "$solaris" == true ]]; then
39-
export PATH=$(echo $PATH | gsed -r "s!${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+)!${SDKMAN_CANDIDATES_DIR}/${candidate}/${VERSION}!g")
38+
export PATH=$(echo $PATH | gsed -r "s!${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+)!${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}!g")
4039

4140
elif [[ "$darwin" == true ]]; then
42-
export PATH=$(echo $PATH | sed -E "s!${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+)!${SDKMAN_CANDIDATES_DIR}/${candidate}/${VERSION}!g")
41+
export PATH=$(echo $PATH | sed -E "s!${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+)!${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}!g")
4342

4443
else
45-
export PATH=$(echo "$PATH" | sed -r "s!${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+)!${SDKMAN_CANDIDATES_DIR}/${candidate}/${VERSION}!g")
44+
export PATH=$(echo "$PATH" | sed -r "s!${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+)!${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}!g")
4645
fi
4746

4847
if [[ ! (-L "${SDKMAN_CANDIDATES_DIR}/${candidate}/current" || -d "${SDKMAN_CANDIDATES_DIR}/${candidate}/current") ]]; then
49-
__sdkman_echo_green "Setting ${candidate} version ${VERSION} as default."
50-
__sdkman_link_candidate_version "$candidate" "$VERSION"
48+
__sdkman_echo_green "Setting ${candidate} version ${version} as default."
49+
__sdkman_link_candidate_version "$candidate" "$version"
5150
fi
5251

5352
echo ""
54-
__sdkman_echo_green "Using ${candidate} version ${VERSION} in this shell."
53+
__sdkman_echo_green "Using ${candidate} version ${version} in this shell."
5554
}

src/test/cucumber/offline_mode.feature

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ Feature: Offline Mode
7676
When I enter "sdk list grails"
7777
Then I see "Offline: only showing installed grails versions"
7878

79-
# use version
80-
81-
Scenario: Use an uninstalled candidate version while in Offline Mode
82-
Given offline mode is enabled with reachable internet
83-
And the candidate "grails" version "1.3.9" is already installed and default
84-
And the candidate "grails" version "2.1.0" is not installed
85-
And an initialised environment
86-
And the system is bootstrapped
87-
When I enter "sdk use grails 2.1.0"
88-
Then I see "Stop! grails 2.1.0 is not available while offline."
89-
9079
# default version
9180

9281
Scenario: Set the default to an uninstalled candidate version while in Offline Mode

src/test/cucumber/service_unavailable.feature

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,6 @@ Feature: Service Unavailable
2828

2929
# use command
3030

31-
Scenario: Use the default candidate version when non selected while Offline
32-
Given the candidate "grails" version "1.3.9" is already installed but not default
33-
And the candidate "grails" version "2.1.0" is already installed but not default
34-
And the system is bootstrapped
35-
When I enter "sdk use grails"
36-
Then I see "No candidate version provided."
37-
38-
Scenario: Use an uninstalled candidate version while Offline
39-
Given the candidate "grails" version "1.3.9" is already installed and default
40-
And the candidate "grails" version "2.1.0" is not installed
41-
And the system is bootstrapped
42-
When I enter "sdk use grails 2.1.0"
43-
Then I see "Stop! grails 2.1.0 is not available while offline."
44-
45-
Scenario: Use an invalid candidate version while Offline
46-
Given the candidate "grails" version "1.3.9" is already installed and default
47-
And the system is bootstrapped
48-
When I enter "sdk use grails 9.9.9"
49-
Then I see "Stop! grails 9.9.9 is not available while offline."
50-
5131
Scenario: Use an installed candidate version while Offline
5232
Given the candidate "grails" version "2.1.0" is already installed and default
5333
And the candidate "grails" version "1.3.9" is already installed but not default

src/test/cucumber/use_version.feature

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,10 @@ Feature: Use Version
2020
And the candidate "grails" version "2.1.0" should be the default
2121

2222
Scenario: Use a candidate version that is not installed
23-
Given the candidate "grails" version "1.3.9" is available for download
24-
And the system is bootstrapped
25-
When I enter "sdk use grails 1.3.9"
26-
Then I see "Stop! grails 1.3.9 is not installed."
27-
And the exit code is 1
28-
29-
Scenario: Use a candidate version that does not exist
3023
Given the candidate "groovy" version "1.9.9" is not available for download
3124
And the system is bootstrapped
3225
When I enter "sdk use groovy 1.9.9"
33-
Then I see "Stop! groovy 1.9.9 is not available."
26+
Then I see "Stop! groovy 1.9.9 is not installed."
3427

3528
Scenario: Use a candidate version that only exists locally
3629
Given the candidate "grails" version "2.0.0.M1" is not available for download

0 commit comments

Comments
 (0)