@@ -31,6 +31,7 @@ struct test_auth_ssh_data {
3131 const char * username ;
3232 const char * pubkey_path ;
3333 const char * privkey_path ;
34+ int check_banner ;
3435};
3536
3637int TEST_PORT = 10050 ;
@@ -50,6 +51,17 @@ auth_password(const char *username, const char *hostname, void *priv)
5051 }
5152}
5253
54+ static void
55+ check_banner (const struct nc_session * session )
56+ {
57+ const char * banner ;
58+
59+ banner = nc_session_ssh_get_banner (session );
60+ assert_non_null (banner );
61+
62+ assert_string_equal (banner , "SSH-2.0-test-banner" );
63+ }
64+
5365static void *
5466client_thread_ssh (void * arg )
5567{
@@ -78,6 +90,10 @@ client_thread_ssh(void *arg)
7890 session = nc_connect_ssh ("127.0.0.1" , TEST_PORT , NULL );
7991 assert_non_null (session );
8092
93+ if (test_data -> check_banner ) {
94+ check_banner (session );
95+ }
96+
8197 nc_session_free (session , NULL );
8298 return NULL ;
8399}
@@ -232,6 +248,29 @@ test_nc_auth_ssh_ed25519_pubkey(void **state)
232248 }
233249}
234250
251+ static void
252+ test_nc_auth_ssh_banner (void * * state )
253+ {
254+ int ret , i ;
255+ pthread_t tids [2 ];
256+ struct ln2_test_ctx * test_ctx = * state ;
257+ struct test_auth_ssh_data * test_data = test_ctx -> test_data ;
258+
259+ test_data -> username = "test_ed25519" ;
260+ test_data -> pubkey_path = TESTS_DIR "/data/id_ed25519.pub" ;
261+ test_data -> privkey_path = TESTS_DIR "/data/id_ed25519" ;
262+ test_data -> check_banner = 1 ;
263+
264+ ret = pthread_create (& tids [0 ], NULL , client_thread_ssh , * state );
265+ assert_int_equal (ret , 0 );
266+ ret = pthread_create (& tids [1 ], NULL , ln2_glob_test_server_thread , * state );
267+ assert_int_equal (ret , 0 );
268+
269+ for (i = 0 ; i < 2 ; i ++ ) {
270+ pthread_join (tids [i ], NULL );
271+ }
272+ }
273+
235274static int
236275setup_ssh (void * * state )
237276{
@@ -274,6 +313,10 @@ setup_ssh(void **state)
274313 ret = nc_server_config_add_ssh_user_password (test_ctx -> ctx , "endpt" , "test_pw" , "testpw" , & tree );
275314 assert_int_equal (ret , 0 );
276315
316+ ret = lyd_new_path (tree , test_ctx -> ctx , "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint[name='endpt']/ssh/"
317+ "ssh-server-parameters/server-identity/libnetconf2-netconf-server:banner" , "test-banner" , 0 , NULL );
318+ assert_int_equal (ret , 0 );
319+
277320 ret = lyd_new_path (tree , test_ctx -> ctx , "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint[name='endpt']/ssh/"
278321 "ssh-server-parameters/client-authentication/users/user[name='test_none']/none" , NULL , 0 , NULL );
279322 assert_int_equal (ret , 0 );
@@ -297,7 +340,8 @@ main(void)
297340 cmocka_unit_test_setup_teardown (test_nc_auth_ssh_ec256_pubkey , setup_ssh , ln2_glob_test_teardown ),
298341 cmocka_unit_test_setup_teardown (test_nc_auth_ssh_ec384_pubkey , setup_ssh , ln2_glob_test_teardown ),
299342 cmocka_unit_test_setup_teardown (test_nc_auth_ssh_ec521_pubkey , setup_ssh , ln2_glob_test_teardown ),
300- cmocka_unit_test_setup_teardown (test_nc_auth_ssh_ed25519_pubkey , setup_ssh , ln2_glob_test_teardown )
343+ cmocka_unit_test_setup_teardown (test_nc_auth_ssh_ed25519_pubkey , setup_ssh , ln2_glob_test_teardown ),
344+ cmocka_unit_test_setup_teardown (test_nc_auth_ssh_banner , setup_ssh , ln2_glob_test_teardown )
301345 };
302346
303347 /* try to get ports from the environment, otherwise use the default */
0 commit comments