Test whether we correctly generate the certificates.
(node_factory)
| 79 | |
| 80 | |
| 81 | def test_generate_certificate(node_factory): |
| 82 | """Test whether we correctly generate the certificates.""" |
| 83 | # when `clnrest-protocol` is `http`, certs are not generated at `clnrest-certs` path |
| 84 | rest_port = str(node_factory.get_unused_port()) |
| 85 | rest_protocol = 'http' |
| 86 | rest_certs = node_factory.directory + '/clnrest-certs' |
| 87 | l1 = node_factory.get_node(options={'clnrest-port': rest_port, |
| 88 | 'clnrest-protocol': rest_protocol, |
| 89 | 'clnrest-certs': rest_certs}) |
| 90 | |
| 91 | assert not Path(rest_certs).exists() |
| 92 | |
| 93 | # node l1 not started |
| 94 | rest_port = str(node_factory.get_unused_port()) |
| 95 | rest_certs = node_factory.directory + '/clnrest-certs' |
| 96 | l1 = node_factory.get_node(options={'clnrest-port': rest_port, |
| 97 | 'clnrest-certs': rest_certs}, start=False) |
| 98 | rest_certs_path = Path(rest_certs) |
| 99 | files = [rest_certs_path / f for f in [ |
| 100 | 'ca.pem', |
| 101 | 'ca-key.pem', |
| 102 | 'client.pem', |
| 103 | 'client-key.pem', |
| 104 | 'server-key.pem', |
| 105 | 'server.pem', |
| 106 | ]] |
| 107 | |
| 108 | # before starting no files exist. |
| 109 | assert [f.exists() for f in files] == [False] * len(files) |
| 110 | |
| 111 | # certificates generated at startup |
| 112 | l1.start() |
| 113 | wait_for(lambda: [f.exists() for f in files] == [True] * len(files)) |
| 114 | |
| 115 | # the files exist, restarting should not change them |
| 116 | contents = [f.read_bytes() for f in files] |
| 117 | l1.restart() |
| 118 | assert contents == [f.read_bytes() for f in files] |
| 119 | |
| 120 | # remove client.pem file, so all certs are regenerated at restart |
| 121 | files[2].unlink() |
| 122 | l1.restart() |
| 123 | wait_for(lambda: [f.exists() for f in files] == [True] * len(files)) |
| 124 | contents_1 = [f.read_bytes() for f in files] |
| 125 | assert [c[0] != c[1] for c in zip(contents, contents_1)] == [True] * len(files) |
| 126 | |
| 127 | # remove client-key.pem file, so all certs are regenerated at restart |
| 128 | files[3].unlink() |
| 129 | l1.restart() |
| 130 | wait_for(lambda: [f.exists() for f in files] == [True] * len(files)) |
| 131 | contents_2 = [f.read_bytes() for f in files] |
| 132 | assert [c[0] != c[1] for c in zip(contents, contents_2)] == [True] * len(files) |
| 133 | |
| 134 | |
| 135 | def start_node_with_clnrest(node_factory, plugin=None, protocol='https'): |
nothing calls this directly
no test coverage detected