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

Exit with error on malformed compose version #6480

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion compose/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def version(self):
'Version in "{}" is invalid - it should be a string.'
.format(self.filename))

if version == '1':
version = version.strip()

if version in ['0', '1'] or not all(n.isdigit() for n in version.split('.')):
raise ConfigurationError(
'Version in "{}" is invalid. {}'
.format(self.filename, VERSION_EXPLANATION)
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,40 @@ def test_version_1_is_invalid(self):
assert 'Version in "filename.yml" is invalid' in excinfo.exconly()
assert VERSION_EXPLANATION in excinfo.exconly()

def test_malformed_version(self):
with pytest.raises(ConfigurationError) as excinfo:
config.load(
build_config_details(
{
'version': '0',
'web': {'image': 'busybox'},
},
filename='filename.yml',
)
)

assert 'Version in "filename.yml" is invalid' in excinfo.exconly()
assert VERSION_EXPLANATION in excinfo.exconly()

def test_malformed_version2(self):
with pytest.raises(ConfigurationError) as excinfo:
config.load(
build_config_details(
{
'version': '3 .0',
'web': {'image': 'busybox'},
},
filename='filename.yml',
)
)

assert 'Version in "filename.yml" is invalid' in excinfo.exconly()
assert VERSION_EXPLANATION in excinfo.exconly()

def test_version_with_trailing_space(self):
cfg = config.load(build_config_details({'version': '3 '}))
assert cfg.version == V3_0

def test_v1_file_with_version_is_invalid(self):
with pytest.raises(ConfigurationError) as excinfo:
config.load(
Expand Down