mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
test: add permissions to auth test
Ass some permissions to the media factory in the test.
This commit is contained in:
parent
d7dec33328
commit
16cfb7b8c0
1 changed files with 37 additions and 9 deletions
|
@ -65,8 +65,7 @@ main (int argc, char *argv[])
|
||||||
GstRTSPToken *token;
|
GstRTSPToken *token;
|
||||||
gchar *basic;
|
gchar *basic;
|
||||||
GstStructure *s;
|
GstStructure *s;
|
||||||
gchar *role_user[] = { "user", NULL };
|
GstRTSPPermissions *permissions;
|
||||||
gchar *role_admin[] = { "admin", NULL };
|
|
||||||
|
|
||||||
gst_init (&argc, &argv);
|
gst_init (&argc, &argv);
|
||||||
|
|
||||||
|
@ -90,10 +89,28 @@ main (int argc, char *argv[])
|
||||||
"x264enc ! rtph264pay name=pay0 pt=96 "
|
"x264enc ! rtph264pay name=pay0 pt=96 "
|
||||||
"audiotestsrc ! audio/x-raw,rate=8000 ! "
|
"audiotestsrc ! audio/x-raw,rate=8000 ! "
|
||||||
"alawenc ! rtppcmapay name=pay1 pt=97 " ")");
|
"alawenc ! rtppcmapay name=pay1 pt=97 " ")");
|
||||||
|
|
||||||
/* attach the test factory to the /test url */
|
/* attach the test factory to the /test url */
|
||||||
gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
|
gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
|
||||||
|
|
||||||
|
/* allow user and admin to access this resource */
|
||||||
|
permissions = gst_rtsp_permissions_new ();
|
||||||
|
gst_rtsp_permissions_add_role (permissions, "user",
|
||||||
|
gst_structure_new ("user",
|
||||||
|
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||||
|
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
|
||||||
|
gst_rtsp_permissions_add_role (permissions, "admin",
|
||||||
|
gst_structure_new ("admin",
|
||||||
|
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||||
|
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
|
||||||
|
/* admin2 can look at the media but not construct so he gets a
|
||||||
|
* 401 Unauthorized */
|
||||||
|
gst_rtsp_permissions_add_role (permissions, "admin2",
|
||||||
|
gst_structure_new ("admin2",
|
||||||
|
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||||
|
"media.factory.construct", G_TYPE_BOOLEAN, FALSE, NULL));
|
||||||
|
gst_rtsp_media_factory_set_permissions (factory, permissions);
|
||||||
|
gst_rtsp_permissions_unref (permissions);
|
||||||
|
|
||||||
/* make another factory */
|
/* make another factory */
|
||||||
factory = gst_rtsp_media_factory_new ();
|
factory = gst_rtsp_media_factory_new ();
|
||||||
gst_rtsp_media_factory_set_launch (factory, "( "
|
gst_rtsp_media_factory_set_launch (factory, "( "
|
||||||
|
@ -102,6 +119,17 @@ main (int argc, char *argv[])
|
||||||
/* attach the test factory to the /test url */
|
/* attach the test factory to the /test url */
|
||||||
gst_rtsp_mount_points_add_factory (mounts, "/test2", factory);
|
gst_rtsp_mount_points_add_factory (mounts, "/test2", factory);
|
||||||
|
|
||||||
|
/* allow admin2 to access this resource */
|
||||||
|
permissions = gst_rtsp_permissions_new ();
|
||||||
|
/* user and admin have no permissions so they can't even see the
|
||||||
|
* media and get a 404 Not Found */
|
||||||
|
gst_rtsp_permissions_add_role (permissions, "admin2",
|
||||||
|
gst_structure_new ("admin2",
|
||||||
|
"media.factory.access", G_TYPE_BOOLEAN, TRUE,
|
||||||
|
"media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL));
|
||||||
|
gst_rtsp_media_factory_set_permissions (factory, permissions);
|
||||||
|
gst_rtsp_permissions_unref (permissions);
|
||||||
|
|
||||||
/* don't need the ref to the mapper anymore */
|
/* don't need the ref to the mapper anymore */
|
||||||
g_object_unref (mounts);
|
g_object_unref (mounts);
|
||||||
|
|
||||||
|
@ -111,8 +139,8 @@ main (int argc, char *argv[])
|
||||||
/* make user token */
|
/* make user token */
|
||||||
token = gst_rtsp_token_new ();
|
token = gst_rtsp_token_new ();
|
||||||
s = gst_rtsp_token_writable_structure (token);
|
s = gst_rtsp_token_writable_structure (token);
|
||||||
gst_structure_set (s, "manager.role", G_TYPE_STRING, "user", NULL);
|
gst_structure_set (s, "resources.class", G_TYPE_STRING, "user", NULL);
|
||||||
gst_structure_set (s, "factory.media.roles", G_TYPE_STRV, role_user, NULL);
|
gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "user", NULL);
|
||||||
basic = gst_rtsp_auth_make_basic ("user", "password");
|
basic = gst_rtsp_auth_make_basic ("user", "password");
|
||||||
gst_rtsp_auth_add_basic (auth, basic, token);
|
gst_rtsp_auth_add_basic (auth, basic, token);
|
||||||
g_free (basic);
|
g_free (basic);
|
||||||
|
@ -121,8 +149,8 @@ main (int argc, char *argv[])
|
||||||
/* make admin token */
|
/* make admin token */
|
||||||
token = gst_rtsp_token_new ();
|
token = gst_rtsp_token_new ();
|
||||||
s = gst_rtsp_token_writable_structure (token);
|
s = gst_rtsp_token_writable_structure (token);
|
||||||
gst_structure_set (s, "manager.role", G_TYPE_STRING, "admin", NULL);
|
gst_structure_set (s, "resources.class", G_TYPE_STRING, "admin", NULL);
|
||||||
gst_structure_set (s, "factory.media.roles", G_TYPE_STRV, role_admin, NULL);
|
gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "admin", NULL);
|
||||||
basic = gst_rtsp_auth_make_basic ("admin", "power");
|
basic = gst_rtsp_auth_make_basic ("admin", "power");
|
||||||
gst_rtsp_auth_add_basic (auth, basic, token);
|
gst_rtsp_auth_add_basic (auth, basic, token);
|
||||||
g_free (basic);
|
g_free (basic);
|
||||||
|
@ -131,8 +159,8 @@ main (int argc, char *argv[])
|
||||||
/* make admin2 token */
|
/* make admin2 token */
|
||||||
token = gst_rtsp_token_new ();
|
token = gst_rtsp_token_new ();
|
||||||
s = gst_rtsp_token_writable_structure (token);
|
s = gst_rtsp_token_writable_structure (token);
|
||||||
gst_structure_set (s, "manager.role", G_TYPE_STRING, "admin", NULL);
|
gst_structure_set (s, "resources.class", G_TYPE_STRING, "admin", NULL);
|
||||||
gst_structure_set (s, "factory.media.roles", G_TYPE_STRV, role_admin, NULL);
|
gst_structure_set (s, "media.factory.role", G_TYPE_STRING, "admin2", NULL);
|
||||||
basic = gst_rtsp_auth_make_basic ("admin2", "power2");
|
basic = gst_rtsp_auth_make_basic ("admin2", "power2");
|
||||||
gst_rtsp_auth_add_basic (auth, basic, token);
|
gst_rtsp_auth_add_basic (auth, basic, token);
|
||||||
g_free (basic);
|
g_free (basic);
|
||||||
|
|
Loading…
Reference in a new issue