1
+ /*
2
+ * Copyright (c) 2020, Arduino SA, All Rights Reserved
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ * not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include " mbed.h"
19
+ #include " TLSSocket.h"
20
+ #include " greentea-client/test_env.h"
21
+ #include " unity/unity.h"
22
+ #include " utest.h"
23
+ #include " tls_tests.h"
24
+ #include " HeapBlockDevice.h"
25
+ #include " LittleFileSystem.h"
26
+
27
+ using namespace utest ::v1;
28
+
29
+ void TLSSOCKET_CERT_IN_FILESYSTEM ()
30
+ {
31
+ SKIP_IF_TCP_UNSUPPORTED ();
32
+
33
+ HeapBlockDevice bd (1024 * 10 );
34
+ LittleFileSystem fs (" fs" );
35
+ TEST_ASSERT_EQUAL (0 , fs.format (&bd));
36
+ TEST_ASSERT_EQUAL (0 , fs.mount (&bd));
37
+
38
+ FILE *fp = fopen (" /fs/certs.pem" , " wb" );
39
+ int ret = fwrite (tls_global::cert, strlen (tls_global::cert), 1 , fp);
40
+ fclose (fp);
41
+
42
+ TLSSocket sock;
43
+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.open (NetworkInterface::get_default_instance ()));
44
+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.set_root_ca_cert_path (" /fs" ));
45
+
46
+ SocketAddress a;
47
+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, NetworkInterface::get_default_instance ()->gethostbyname (ECHO_SERVER_ADDR, &a));
48
+ a.set_port (ECHO_SERVER_PORT_TLS);
49
+ TEST_ASSERT_EQUAL (NSAPI_ERROR_OK, sock.connect (a));
50
+ }
0 commit comments