From a1d8dcdcb9574ac4de4be4cf282b8964983da78e Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Tue, 30 Jun 2020 09:45:07 -0300 Subject: [PATCH] Change permissions implementation for JWT claims Also improve some tests cases --- .../PetOrdersRESTfulControllerTest.class.st | 6 +++--- .../PetsRESTfulControllerTest.class.st | 10 +++++----- source/Stargate-Model/JWTClaimsSet.extension.st | 10 +++------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st index 3e6652b..50065d4 100644 --- a/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st @@ -311,7 +311,7 @@ PetOrdersRESTfulControllerTest >> testGetCanceledOrder [ self assertUrl: json pet equals: self petUrl; assert: json status equals: 'registered'; - assertUrl: json links self equals: 'https://petstore.example.com/orders/1'; + assertUrl: json selfLocation equals: 'https://petstore.example.com/orders/1'; assertUrl: json links cancel equals: 'https://petstore.example.com/orders/1/cancel'; assertUrl: json links complete equals: 'https://petstore.example.com/orders/1/complete'; assert: (resourceController cancelOrderBasedOn: (self requestToPOST: json links cancel identifiedBy: 1) within: self newHttpRequestContext) isSuccess ]; @@ -319,7 +319,7 @@ PetOrdersRESTfulControllerTest >> testGetCanceledOrder [ self assertUrl: json pet equals: self petUrl; assert: json status equals: 'canceled'; - assertUrl: json links self equals: 'https://petstore.example.com/orders/1' ] + assertUrl: json selfLocation equals: 'https://petstore.example.com/orders/1' ] ] { #category : #'tests - comments' } @@ -396,7 +396,7 @@ PetOrdersRESTfulControllerTest >> testGetOrderJustCreated [ self assertUrl: json pet equals: self petUrl; assert: json status equals: 'registered'; - assertUrl: json links self equals: 'https://petstore.example.com/orders/1'; + assertUrl: json selfLocation equals: 'https://petstore.example.com/orders/1'; assertUrl: json links cancel equals: 'https://petstore.example.com/orders/1/cancel'; assertUrl: json links complete equals: 'https://petstore.example.com/orders/1/complete' ] ] diff --git a/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st index c3aa4e2..122f21f 100644 --- a/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st @@ -295,7 +295,7 @@ PetsRESTfulControllerTest >> testGetPetJustCreated [ assert: json name equals: 'Firulais'; assert: json type equals: 'dog'; assert: json status equals: 'new'; - assertUrl: json links self equals: 'https://pets.example.com/pets/1' + assertUrl: json selfLocation equals: 'https://pets.example.com/pets/1' ] ] @@ -333,7 +333,7 @@ PetsRESTfulControllerTest >> testGetPetJustCreatedWhenNoAcceptHeaderPresentInReq do: [ :json | self assert: json name equals: 'Firulais'; - assertUrl: json links self equals: 'https://pets.example.com/pets/1' + assertUrl: json selfLocation equals: 'https://pets.example.com/pets/1' ] ] @@ -382,7 +382,7 @@ PetsRESTfulControllerTest >> testGetPetSummaryJustCreated [ do: [ :json | self assert: json name equals: 'Firulais'; - assertUrl: json links self equals: 'https://pets.example.com/pets/1'; + assertUrl: json selfLocation equals: 'https://pets.example.com/pets/1'; assert: json type isNil; assert: json status isNil ] @@ -586,7 +586,7 @@ PetsRESTfulControllerTest >> testUpdatePetName [ assert: json name equals: 'Mendieta'; assert: json type equals: 'dog'; assert: json status equals: 'new'; - assertUrl: json links self equals: 'https://pets.example.com/pets/1' ] + assertUrl: json selfLocation equals: 'https://pets.example.com/pets/1' ] ] { #category : #'tests - update' } @@ -613,5 +613,5 @@ PetsRESTfulControllerTest >> testUpdatePetStatus [ assert: json name equals: 'Firulais'; assert: json type equals: 'dog'; assert: json status equals: 'gone'; - assertUrl: json links self equals: 'https://pets.example.com/pets/1' ] + assertUrl: json selfLocation equals: 'https://pets.example.com/pets/1' ] ] diff --git a/source/Stargate-Model/JWTClaimsSet.extension.st b/source/Stargate-Model/JWTClaimsSet.extension.st index 39242cb..ae9d2bb 100644 --- a/source/Stargate-Model/JWTClaimsSet.extension.st +++ b/source/Stargate-Model/JWTClaimsSet.extension.st @@ -3,17 +3,13 @@ Extension { #name : #JWTClaimsSet } { #category : #'*Stargate-Model' } JWTClaimsSet >> permissions [ - ^ self scope splitOn: Character space + ^ claims at: 'permissions' ifAbsent: [ ^ #() ] ] { #category : #'*Stargate-Model' } -JWTClaimsSet >> permissions: aStringCollection [ +JWTClaimsSet >> permissions: aCollection [ - self - scope: - ( String - streamContents: - [ :stream | aStringCollection do: [ :string | stream nextPutAll: string ] separatedBy: [ stream space ] ] ) + self at: 'permissions' put: aCollection asArray ] { #category : #'*Stargate-Model' }