blob: 469f3751e0090b801eba654ab128ee823dfccb03 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2024 The Cobalt Authors. All Rights Reserved.
#
# 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.
"""Test for tool for updating Cobalt SSL Certificates."""
import io
import tempfile
import unittest
from tools import update_certs
_CERT_NAME = '8cb5ee0f.0'
_CERT = '''\
-----BEGIN CERTIFICATE-----
MIIBtjCCAVugAwIBAgITBmyf1XSXNmY/Owua2eiedgPySjAKBggqhkjOPQQDAjA5
MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24g
Um9vdCBDQSAzMB4XDTE1MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkG
A1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJvb3Qg
Q0EgMzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCmXp8ZBf8ANm+gBG1bG8lKl
ui2yEujSLtf6ycXYqm0fc4E7O5hrOXwzpcVOho6AF2hiRVd9RFgdszflZwjrZt6j
QjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBSr
ttvXBp43rDCGB5Fwx5zEGbF4wDAKBggqhkjOPQQDAgNJADBGAiEA4IWSoxe3jfkr
BqWTrBqYaGFy+uGh0PsceGCmQ5nFuMQCIQCcAu/xlJyzlvnrxir4tiz+OpAUFteM
YyRIHN8wfdVoOw==
-----END CERTIFICATE-----
'''
class UpdateCertsTest(unittest.TestCase):
def testSplitCerts(self):
pem = io.StringIO(_CERT + _CERT)
output = update_certs.SplitCerts(pem)
self.assertEqual(len(output), 2)
self.assertEqual(output[0], _CERT)
self.assertEqual(output[1], _CERT)
def testUpdateBuild(self):
filepaths = {'foo', 'bar'}
build_content = '''\
network_certs = [
"//bar",
"//foo",
]
'''
with tempfile.NamedTemporaryFile(delete=False) as tmp:
update_certs.UpdateBuild(tmp.name, filepaths)
with open(tmp.name, encoding='utf-8') as f:
self.assertEqual(f.read(), build_content)
if __name__ == '__main__':
unittest.main()