اختبار نقاط النهاية المؤمَّنة
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
test authentication and authorization.
الموضوعات المخطط لها
- Get a real token by logging in during the test (or from a test Keycloak) and send it in the
Authorizationheader. - With MockMvc you can use
@WithMockUseror JWT post-processors from Spring Security Test. - Test each role: allowed, forbidden, and anonymous.
- Test that a user cannot read another user's data.
- Never put real credentials in test code; use test users.
تفاصيل المخطط المبدئي
عرض عملي
given().port(port).header("Authorization", "Bearer " + token)
.when().get("/api/orders/" + otherUsersOrderId)
.then().statusCode(403);اختبر فهمك
A logged-in user opens an admin endpoint. Which status?
أظهر الإجابة
403.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.