@@ -20,6 +20,7 @@ use lib "$main::ww3_dir/t/lib";
2020use Clone qw/ clone/ ;
2121use YAML::XS qw/ LoadFile/ ;
2222use List::MoreUtils qw/ firstval/ ;
23+ use Mojo::JSON qw/ true false/ ;
2324
2425use TestUtils qw/ loadCSV removeIDs/ ;
2526
@@ -33,10 +34,10 @@ my $config = clone(LoadFile($config_file));
3334
3435my $t = Test::Mojo-> new(WeBWorK3 => $config );
3536
36- # Authenticate with the admin user .
37- $t -> post_ok(' /webwork3/api/login' => json => { username => ' admin ' , password => ' admin ' })-> status_is(200)
38- -> content_type_is(' application/json;charset=UTF-8' )-> json_is(' /logged_in' => 1)-> json_is( ' /user/user_id ' => 1)
39- -> json_is(' /user/is_admin' => 1 );
37+ # Authenticate with an instructor .
38+ $t -> post_ok(' /webwork3/api/login' => json => { username => ' lisa ' , password => ' lisa ' })-> status_is(200)
39+ -> content_type_is(' application/json;charset=UTF-8' )-> json_is(' /logged_in' => 1)
40+ -> json_is(' /user/username ' => ' lisa ' ) -> json_is( ' /user/ is_admin' => false );
4041
4142# Load the global settings from the file
4243my $global_settings_from_file = LoadFile(" $main::ww3_dir /conf/course_settings.yml" );
@@ -113,4 +114,29 @@ $t->post_ok('/webwork3/api/global-settings/check-timezone' => json => { timezone
113114$t -> post_ok(' /webwork3/api/global-settings/check-timezone' => json => { timezone => ' Amrica/Chicago' })-> status_is(200)
114115 -> json_is(' /valid_timezone' => false);
115116
117+ # Check to make sure that a student has appropriate access (ralph is a student in Arithmetic-course_id: 4)
118+
119+ $t -> post_ok(' /webwork3/api/logout' )-> status_is(200);
120+ $t -> post_ok(' /webwork3/api/login' => json => { username => ' ralph' , password => ' ralph' })-> status_is(200);
121+
122+ # A student should have access to the global settings;
123+ $t -> get_ok(' /webwork3/api/global-settings' )-> content_type_is(' application/json;charset=UTF-8' )-> status_is(200);
124+ $t -> get_ok(' /webwork3/api/global-settings/1' )-> content_type_is(' application/json;charset=UTF-8' )-> status_is(200);
125+
126+ # A student should also have access to the course setting overrides for a course they are enrolled in.
127+ $t -> get_ok(' /webwork3/api/courses/4/settings' )-> content_type_is(' application/json;charset=UTF-8' )-> status_is(200);
128+
129+ # But not from a course they are not enrolled in
130+ $t -> get_ok(' /webwork3/api/courses/5/settings' )-> content_type_is(' application/json;charset=UTF-8' )-> status_is(403);
131+
132+ # A student shouldn't be able to update a course setting
133+ $t -> put_ok(
134+ " /webwork3/api/courses/4/settings/$reduced_scoring ->{setting_id}" => json => {
135+ value => 0.5
136+ }
137+ )-> status_is(403);
138+
139+ # Nor delete a course setting
140+ $t -> delete_ok(" /webwork3/api/courses/4/settings/$reduced_scoring ->{setting_id}" )-> status_is(403);
141+
116142done_testing;
0 commit comments