Skip to content

A free open source IT asset/license management system

Fixed RB-22018 - SCIM /Me endpoint returning 500 sometimes

snipe734a87941275
diff --git a/app/Models/User.php b/app/Models/User.php
index 46ec1e7794..9567761d6f 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -678,6 +678,17 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
];
}
+ /**
+ * SCIM library shim. This could maybe be moved into the user model itself,
+ * but since it hooks into arietimmerman's library, this was the easier path
+ * without pulling it into traits. Returns the primary key so a scim-client
+ * fetch of /Me matches the shape of a fetch of /Users/{id}
+ */
+ public function getUserId(): int
+ {
+ return (int) $this->id;
+ }
+
/**
* The association-blocker half of isDeletable(): true only when the
* user has no assigned assets / accessories / licenses / consumables
diff --git a/tests/Feature/Scim/MeEndpointTest.php b/tests/Feature/Scim/MeEndpointTest.php
new file mode 100644
index 0000000000..ead38226d2
--- /dev/null
+++ b/tests/Feature/Scim/MeEndpointTest.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Tests\Feature\Scim;
+
+use App\Models\User;
+use Laravel\Passport\Passport;
+use Tests\TestCase;
+
+
+class MeEndpointTest extends TestCase
+{
+ public function test_scim_me_returns_the_authenticated_user()
+ {
+ $me = User::factory()->superuser()->create([
+ 'email' => '[email protected]',
+ 'first_name' => 'Ada',
+ 'last_name' => 'Lovelace',
+ ]);
+ Passport::actingAs($me);
+
+ $response = $this->getJson('/scim/v2/Me')->assertOk();
+ $this->assertSame((string) $me->id, $response->json('id'));
+
+ $this->assertSame('[email protected]', $response->json('emails.0.value'));
+ }
+
+ public function test_scim_me_matches_users_endpoint_for_same_subject()
+ {
+
+ $me = User::factory()->superuser()->create();
+ Passport::actingAs($me);
+
+ $meBody = $this->getJson('/scim/v2/Me')->assertOk()->json();
+ $userBody = $this->getJson('/scim/v2/Users/'.$me->id)->assertOk()->json();
+
+ $this->assertSame($userBody['id'], $meBody['id']);
+ $this->assertSame($userBody['userName'] ?? null, $meBody['userName'] ?? null);
+ }
+}