From a16ccac1d9a8a8c16d2f74e0d16f83463e0faab5 Mon Sep 17 00:00:00 2001 From: Joe Subbiani Date: Thu, 22 Jul 2021 18:52:17 +0100 Subject: [PATCH] Format files and add license comment Changes to pass tests/scripts/check_files.py -Add missing new line at end of each file -Remove any trailing whitespaces -Added file shebang comments Added license info and purpose of file descriptions. The 2 test_translate... files may not be stay later down the line, but incase they do become permanent, it is good to add the appropriate comments now. Signed-off-by: Joe Subbiani --- tests/test_translate_format.sh | 33 ++++++++++++++++++++++++++++++-- tests/test_translate_names.py | 27 ++++++++++++++++++++++++-- tests/translate_ciphers.py | 35 ++++++++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/tests/test_translate_format.sh b/tests/test_translate_format.sh index 43b7ff4e3..55d8a8a8e 100755 --- a/tests/test_translate_format.sh +++ b/tests/test_translate_format.sh @@ -1,5 +1,34 @@ #!/bin/sh +# test_translate_format.sh +# +# Copyright The Mbed TLS Contributors +# SPDX-License-Identifier: Apache-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. +# +# Purpose +# +# Test translate_ciphers.py formatting by comparing the translated +# ciphersuite names to the true names. As in compat.sh, the spaces between +# the ciphersuite names are normalised. +# +# On fail, the translated cipher suite names do not match the correct ones. +# In this case the difference will be printed in stdout. +# +# This files main purpose is to ensure translate_ciphers.py can take strings +# in the expected format and return them in the format compat.sh will expect. + # Ciphers that will use translate_ciphers.py M_CIPHERS="" O_CIPHERS="" @@ -19,7 +48,7 @@ CIPHERS="TLS-ECDHE-ECDSA-WITH-NULL-SHA \ M_CIPHERS="$M_CIPHERS \ $CIPHERS" - + G=`python3 translate_ciphers.py g "$CIPHERS"` G_CIPHERS="$G_CIPHERS \ $G" @@ -110,4 +139,4 @@ if [ "$Ot_CIPHERS" != "$O_CIPHERS" ] then echo "OpenSSL Translated: $O_CIPHERS" echo "OpenSSL Original: $Ot_CIPHERS" -fi \ No newline at end of file +fi diff --git a/tests/test_translate_names.py b/tests/test_translate_names.py index 9de283059..d018c1091 100755 --- a/tests/test_translate_names.py +++ b/tests/test_translate_names.py @@ -1,3 +1,28 @@ +#!/usr/bin/env python3 + +# test_translate_names.py +# +# Copyright The Mbed TLS Contributors +# SPDX-License-Identifier: Apache-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. +# +# Purpose +# +# Test translate_ciphers.py by running every MBedTLS ciphersuite name +# combination through the translate functions and comparing them to their +# correct GNU or OpenSSL counterpart. + from translate_ciphers import * def assert_equal(translate, original): @@ -235,7 +260,6 @@ def test_mbed_ossl_common(): o = translate_ossl(m_ciphers[i]) assert_equal(o, o_ciphers[i]) - def test_mbed_gnu_common(): m_ciphers = [ "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA256", @@ -420,7 +444,6 @@ def test_mbed_gnu_common(): g = translate_gnu(m_ciphers[i]) assert_equal(g, g_ciphers[i]) - test_all_common() test_mbed_ossl_common() diff --git a/tests/translate_ciphers.py b/tests/translate_ciphers.py index b9a2d5374..07affb290 100755 --- a/tests/translate_ciphers.py +++ b/tests/translate_ciphers.py @@ -1,3 +1,34 @@ +#!/usr/bin/env python3 + +# translate_ciphers.py +# +# Copyright The Mbed TLS Contributors +# SPDX-License-Identifier: Apache-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. +# +# Purpose +# +# Translate ciphersuite names in MBedTLS format to OpenSSL and GNU +# standards. +# +# Format and analyse strings past in via input arguments to match +# the expected strings utilised in compat.sh. +# +# sys.argv[1] should be "g" or "o" for GNU or OpenSSL. +# sys.argv[2] should be a string containing one or more +# ciphersuite names. + import re import sys @@ -91,8 +122,8 @@ def main(): elif sys.argv[1] == "o": print(format_o(sys.argv[2])) exit(0) - else: + else: exit(1) if __name__ == "__main__": - main() \ No newline at end of file + main()