Skip to content

Commit

Permalink
Test enforce IMDSv2
Browse files Browse the repository at this point in the history
  • Loading branch information
NihalM99 committed Oct 12, 2023
1 parent a396f5f commit 686abf3
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/test_help_texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import sys
import threading
import types
import yaml

from ebcli.core import fileoperations
from ebcli.core import io
Expand Down Expand Up @@ -1701,11 +1702,20 @@ def setUpClass(cls):
'my-custom-platform',
workspace_type='Platform'
)
cls.enforce_imdsv2()

@classmethod
def tearDownClass(cls):
os.chdir(cls.root_dir)

@classmethod
def enforce_imdsv2(cls):
config_path = os.path.join(os.getcwd(), '.elasticbeanstalk', 'config.yml')
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
config['settings']['aws:autoscaling:launchconfiguration']['DisableIMDSv1'] = 'true'
with open(config_path, 'w') as file:
yaml.safe_dump(config, file)

class ApplicationWorkspaceTests(TestHelpTexts, HelpTestsMixin):
@classmethod
Expand All @@ -1722,11 +1732,21 @@ def setUpClass(cls):
'php-7.2',
workspace_type='Application'
)
cls.enforce_imdsv2()

@classmethod
def tearDownClass(cls):
os.chdir(cls.root_dir)

@classmethod
def enforce_imdsv2(cls):
config_path = os.path.join(os.getcwd(), '.elasticbeanstalk', 'config.yml')
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
config['settings']['aws:autoscaling:launchconfiguration']['DisableIMDSv1'] = 'true'
with open(config_path, 'w') as file:
yaml.safe_dump(config, file)


class NoWorkspaceTests(TestHelpTexts, HelpTestsMixin):
@classmethod
Expand All @@ -1746,10 +1766,20 @@ def setUpClass(cls):
)
except fileoperations.NotInitializedError:
pass

cls.enforce_imdsv2

@classmethod
def tearDownClass(cls):
os.chdir(cls.root_dir)

@classmethod
def enforce_imdsv2(cls):
config_path = os.path.join(os.getcwd(), '.elasticbeanstalk', 'config.yml')
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
config['settings']['aws:autoscaling:launchconfiguration']['DisableIMDSv1'] = 'true'
with open(config_path, 'w') as file:
yaml.safe_dump(config, file)


if __name__ == '__main__':
Expand Down

0 comments on commit 686abf3

Please sign in to comment.