Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 20... Línea 20...
20
 * External auth oauth2 API tests.
20
 * External auth oauth2 API tests.
21
 *
21
 *
22
 * @package     auth_oauth2
22
 * @package     auth_oauth2
23
 * @copyright   2017 Damyon Wiese
23
 * @copyright   2017 Damyon Wiese
24
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
25
 *
-
 
26
 * @covers \auth_oauth2\api
25
 */
27
 */
26
class api_test extends \advanced_testcase {
28
final class api_test extends \advanced_testcase {
Línea 27... Línea 29...
27
 
29
 
28
    /**
30
    /**
29
     * Test the cleaning of orphaned linked logins for all issuers.
31
     * Test the cleaning of orphaned linked logins for all issuers.
30
     */
32
     */
Línea 135... Línea 137...
135
 
137
 
136
        $this->setAdminUser();
138
        $this->setAdminUser();
Línea 137... Línea 139...
137
        $issuer = \core\oauth2\api::create_standard_issuer('google');
139
        $issuer = \core\oauth2\api::create_standard_issuer('google');
-
 
140
 
Línea 138... Línea 141...
138
 
141
        $user = $this->getDataGenerator()->create_user();
139
        $user = $this->getDataGenerator()->create_user();
142
        $this->setUser($user);
140
 
143
 
Línea 168... Línea 171...
168
 
171
 
169
        $this->assertEquals($newuser->id, $match->get('userid'));
172
        $this->assertEquals($newuser->id, $match->get('userid'));
Línea 170... Línea 173...
170
    }
173
    }
-
 
174
 
-
 
175
    /**
-
 
176
     * Test that we cannot deleted a linked login for another user
-
 
177
     */
-
 
178
    public function test_delete_linked_login_other_user(): void {
-
 
179
        $this->resetAfterTest();
-
 
180
 
-
 
181
        $this->setAdminUser();
-
 
182
        $issuer = \core\oauth2\api::create_standard_issuer('google');
-
 
183
 
-
 
184
        $user = $this->getDataGenerator()->create_user();
-
 
185
 
-
 
186
        api::link_login([
-
 
187
            'username' => 'banana',
-
 
188
            'email' => 'banana@example.com',
-
 
189
        ], $issuer, $user->id);
-
 
190
 
-
 
191
        /** @var linked_login $linkedlogin */
-
 
192
        $linkedlogin = api::get_linked_logins($user->id)[0];
-
 
193
 
-
 
194
        // We are logged in as a different user, so cannot delete this.
-
 
195
        $this->expectException(\dml_missing_record_exception::class);
-
 
196
        api::delete_linked_login($linkedlogin->get('id'));
-
 
197
    }
171
 
198
 
172
    /**
199
    /**
173
     * Test that is_enabled correctly identifies when the plugin is enabled.
200
     * Test that is_enabled correctly identifies when the plugin is enabled.
174
     */
201
     */
Línea 225... Línea 252...
225
        }
252
        }
Línea 226... Línea 253...
226
 
253
 
227
        // Explicitly test the user is not yet confirmed.
254
        // Explicitly test the user is not yet confirmed.
228
        $this->assertEquals(0, $userdata->confirmed);
255
        $this->assertEquals(0, $userdata->confirmed);
-
 
256
    }
-
 
257
 
-
 
258
    /**
-
 
259
     * Test case for checking the email greetings in OAuth2 confirmation emails.
-
 
260
     */
-
 
261
    public function test_email_greetings(): void {
-
 
262
        $this->resetAfterTest();
-
 
263
        $this->setAdminUser();
-
 
264
 
-
 
265
        $issuer = \core\oauth2\api::create_standard_issuer('microsoft');
-
 
266
 
-
 
267
        $userinfo = [];
-
 
268
        $userinfo['username'] = 'apple';
-
 
269
        $userinfo['email'] = 'apple@example.com';
-
 
270
        $userinfo['firstname'] = 'Apple';
-
 
271
        $userinfo['lastname'] = 'Fruit';
-
 
272
        $sink = $this->redirectEmails(); // Make sure we are redirecting emails.
-
 
273
        \auth_oauth2\api::send_confirm_account_email($userinfo, $issuer);
-
 
274
        $result = $sink->get_messages();
-
 
275
        $sink->close();
-
 
276
        // Test greetings.
-
 
277
        $this->assertStringContainsString('Hi ' . $userinfo['firstname'], quoted_printable_decode($result[0]->body));
-
 
278
 
-
 
279
        $userinfo = [];
-
 
280
        $userinfo['username'] = 'banana';
-
 
281
        $userinfo['email'] = 'banana@example.com';
-
 
282
        $userinfo['firstname'] = 'Banana';
-
 
283
        $userinfo['lastname'] = 'Fruit';
-
 
284
        $user = $this->getDataGenerator()->create_user();
-
 
285
        $sink = $this->redirectEmails(); // Make sure we are redirecting emails.
-
 
286
        \auth_oauth2\api::send_confirm_link_login_email($userinfo, $issuer, $user->id);
-
 
287
        $result = $sink->get_messages();
-
 
288
        $sink->close();
-
 
289
        // Test greetings.
-
 
290
        $this->assertStringContainsString('Hi ' . $user->firstname, quoted_printable_decode($result[0]->body));
229
    }
291
    }