-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cli): fixup + test
aws-install
SSH user (#1009)
This commit refactors and adds unit tests for the SSH username assignment logic in the `aws-install` CLI subcommand. Specifically, this commit: * Breaks down the AMI image name fetch and the lookup table code into helper functions * Adds unit tests for these helper functions * Enforces using the username passed as the `--ssh_username` CLI arg Fixes RAIN-42812 Signed-off-by: nschmeller <[email protected]>
- Loading branch information
1 parent
6dbcb23
commit d216771
Showing
3 changed files
with
118 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Author:: Nicholas Schmeller (<[email protected]>) | ||
// Copyright:: Copyright 2022, Lacework Inc. | ||
// License:: Apache License, Version 2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package lwrunner | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const GOOD_SSH_USERNAME = "customer_ssh_username" | ||
|
||
func TestSSHUsernameLookupChecksForCLIArgUsernameFirst(t *testing.T) { | ||
user, err := getSSHUsername(GOOD_SSH_USERNAME, "some_ubuntu_ami") | ||
assert.NoError(t, err) | ||
assert.Equal(t, user, GOOD_SSH_USERNAME) | ||
assert.NotEqual(t, user, "ubuntu") | ||
} | ||
|
||
func TestSSHUsernameLookupChecksEnvBeforeAMI(t *testing.T) { | ||
t.Setenv("LW_SSH_USER", GOOD_SSH_USERNAME) | ||
|
||
user, err := getSSHUsername("", "some_ubuntu_ami") | ||
assert.NoError(t, err) | ||
assert.Equal(t, user, GOOD_SSH_USERNAME) | ||
assert.NotEqual(t, user, "ubuntu") | ||
} | ||
|
||
func TestSSHUsernameLookupFailsOnBadImageName(t *testing.T) { | ||
user, err := getSSHUsername("", "ami_bad_image_name") | ||
assert.Error(t, err) | ||
assert.Empty(t, user) | ||
} |