Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: file permissions for .ask/cli_config and .aws/credentials #94

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/commands/configure/aws-profile-setup-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function _createAwsProfileFlow(config, awsProfileList, callback) {
try {
const awsCredentialsFile = path.join(os.homedir(), CONSTANTS.FILE_PATH.AWS.HIDDEN_FOLDER, CONSTANTS.FILE_PATH.AWS.CREDENTIAL_FILE);
fs.ensureFileSync(awsCredentialsFile);
fs.chmodSync(awsCredentialsFile, CONSTANTS.FILE_PERMISSION.USER_READ_WRITE);
} catch (error) {
return callback(error);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/configure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function _ensureAppConfigInitiated(cmd) {
const configFilePath = path.join(askFolderPath, CONSTANTS.FILE_PATH.ASK.PROFILE_FILE);
if (!fs.existsSync(configFilePath)) {
fs.ensureDirSync(askFolderPath);
jsonfile.writeFileSync(configFilePath, { profiles: {} }, { spaces: CONSTANTS.CONFIGURATION.JSON_DISPLAY_INDENT });
jsonfile.writeFileSync(configFilePath, { profiles: {} }, { spaces: CONSTANTS.CONFIGURATION.JSON_DISPLAY_INDENT,
mode: CONSTANTS.FILE_PERMISSION.USER_READ_WRITE });
}
new AppConfig(configFilePath);
return _buildAskConfig(cmd, askFolderPath, configFilePath);
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,7 @@ module.exports.REGEX_VALIDATIONS = {
module.exports.ASK_DEFAULT_PROFILE_NAME = 'default';
module.exports.AWS_DEFAULT_PROFILE_NAME = 'ask_cli_default';
module.exports.LOCALHOST_PORT = '9090';

module.exports.FILE_PERMISSION = {
USER_READ_WRITE: '0600'
};
4 changes: 4 additions & 0 deletions test/unit/commands/configure/aws-profile-setup-helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe('Command: Configure - AWS profile setup helper test', () => {
});
sinon.stub(fs, 'existsSync').returns(false);
sinon.stub(fs, 'ensureFileSync');
sinon.stub(fs, 'chmodSync');
sinon.stub(stringUtils, 'isNonBlankString').returns(false);
sinon.stub(ui, 'confirmSettingAws').callsArgWith(0, null, true);
sinon.stub(ui, 'addNewCredentials').callsArgWith(0, null, TEST_CREDENTIALS);
Expand Down Expand Up @@ -237,6 +238,7 @@ describe('Command: Configure - AWS profile setup helper test', () => {
sinon.stub(ui, 'requestAwsProfileName').callsArgWith(1, TEST_ERROR_MESSAGE);
sinon.stub(awsProfileHandler, 'listProfiles').returns([TEST_PROFILE]);
sinon.stub(fs, 'ensureFileSync');
sinon.stub(fs, 'chmodSync');
sinon.stub(fs, 'existsSync').returns(true);

// call
Expand All @@ -262,6 +264,7 @@ describe('Command: Configure - AWS profile setup helper test', () => {
sinon.stub(ui, 'addNewCredentials').callsArgWith(0, TEST_ERROR_MESSAGE);
sinon.stub(awsProfileHandler, 'listProfiles').returns([TEST_PROFILE]);
sinon.stub(fs, 'ensureFileSync');
sinon.stub(fs, 'chmodSync');
sinon.stub(fs, 'existsSync').returns(true);

// call
Expand Down Expand Up @@ -289,6 +292,7 @@ describe('Command: Configure - AWS profile setup helper test', () => {
sinon.stub(ui, 'addNewCredentials').callsArgWith(0, null, TEST_CREDENTIALS);
sinon.stub(awsProfileHandler, 'listProfiles').returns([TEST_PROFILE]);
sinon.stub(fs, 'ensureFileSync');
sinon.stub(fs, 'chmodSync');
sinon.stub(fs, 'existsSync').returns(true);
sinon.stub(awsProfileHandler, 'addProfile');
sinon.stub(profileHelper, 'setupProfile');
Expand Down