Skip to content

Commit

Permalink
splitted authorizer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Eichhorn committed Jun 20, 2024
1 parent f8b8fa4 commit cb55912
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 77 deletions.
102 changes: 25 additions & 77 deletions src/SpotifyConnect/SPOCTestAuthorizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,108 +4,43 @@ Class {
#instVars : [
'authorizer'
],
#category : #'SpotifyConnect-Auth-Tests'
#category : #'SpotifyConnect-Tests'
}

{
#category : #accessing,
#'squeak_changestamp' : 'TL 6/10/2024 04:46'
}
SPOCTestAuthorizer >> authorizer [

^ authorizer
]

{
#category : #accessing,
#'squeak_changestamp' : 'TL 6/10/2024 04:46'
}
SPOCTestAuthorizer >> authorizer: anObject [

authorizer := anObject
]

{
#category : #setup,
#'squeak_changestamp' : 'TL 6/10/2024 04:46'
#'squeak_changestamp' : 'VE 6/20/2024 19:50'
}
SPOCTestAuthorizer >> setUp [

self authorizer: SPOCAuthorizer new
authorizer := SPOCAuthorizer new.
]

{
#category : #testing,
#'squeak_changestamp' : 'TL 6/12/2024 00:40'
}
SPOCTestAuthorizer >> testAuthorizationUrl [

| clipboardText responseUrl targetUrl |
responseUrl := self authorizer startAuthorization.
targetUrl := 'https://accounts.spotify.com/authorize',
'?response_type=code',
'&scope=', SPOCAuthorizer scope,
'&redirect_uri=', SPOCAuthorizer redirectUri,
'&state=', self authorizer randomState,
'&client_id=', SPOCAuthorizer clientId.
clipboardText := Clipboard default primitiveClipboardText.
self assert: targetUrl = responseUrl.
self assert: targetUrl = clipboardText
]

{
#category : #testing,
#'squeak_changestamp' : 'TL 6/10/2024 23:16'
}
SPOCTestAuthorizer >> testCallbackEndpoint [

| response |
self authorizer startAuthorization.
response := WebClient httpGet: SPOCAuthorizer redirectUri.
self assert: (response code = 404) not
]

{
#category : #testing,
#'squeak_changestamp' : 'TL 6/10/2024 23:16'
}
SPOCTestAuthorizer >> testCallbackErrors [

| response |
self authorizer startAuthorization.
response := WebClient httpGet: (SPOCAuthorizer redirectUri, '?code=123').
self assert: response code = 400.
response := WebClient httpGet: (SPOCAuthorizer redirectUri, '?state=123').
self assert: response code = 400.
response := WebClient httpGet: (SPOCAuthorizer redirectUri, '?error=error').
self assert: response code = 500
]

{
#category : #testing,
#'squeak_changestamp' : 'TL 6/10/2024 23:16'
#'squeak_changestamp' : 'VE 6/20/2024 19:49'
}
SPOCTestAuthorizer >> testOnAuthorizationSuccessCallbacks [

| tmp |
tmp := 0.
self authorizer registerSuccessCallback: [tmp := 1].
self authorizer callSuccessCallbacks.
authorizer registerSuccessCallback: [tmp := 1].
authorizer callSuccessCallbacks.
self assert: tmp = 1
]

{
#category : #testing,
#'squeak_changestamp' : 'TL 6/10/2024 23:17'
#'squeak_changestamp' : 'VE 6/20/2024 19:49'
}
SPOCTestAuthorizer >> testRandomState [

| lastRandomState |
self authorizer nextRandomState.
self assert: self authorizer randomState isString.
lastRandomState := self authorizer randomState.
self authorizer nextRandomState.
self assert: (lastRandomState = self authorizer randomState) not
authorizer nextRandomState.
self assert: authorizer randomState isString.
lastRandomState := authorizer randomState.
authorizer nextRandomState.
self assert: (lastRandomState = authorizer randomState) not
]

{
Expand All @@ -116,3 +51,16 @@ SPOCTestAuthorizer >> testResponseAsset [

self assert: ((GitAssetLoader for: 'SpotifyConnect') loadString: 'assets/successResponse.html') notNil
]

{
#category : #testing,
#'squeak_changestamp' : 'VE 6/20/2024 20:03'
}
SPOCTestAuthorizer >> testStartAuthorization [

| url entryPoints |
url := authorizer startAuthorization.
entryPoints := WebServer default entryPoints.
self assert: ((entryPoints at: (SPOCAuthorizer redirectRoute)) ~= nil).
self assert: url ~= nil.
]
48 changes: 48 additions & 0 deletions src/SpotifyConnect/SPOCTestAuthorizerProcess.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Class {
#name : #SPOCTestAuthorizerProcess,
#superclass : #SPOCTestCaseWithAuth,
#category : #'SpotifyConnect-Auth-Tests'
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'VE 6/20/2024 19:56'
}
SPOCTestAuthorizerProcess >> testAuthorizationUrl [

| targetUrl url |
url := self auth buildAuthorizationUrl.
targetUrl := 'https://accounts.spotify.com/authorize',
'?response_type=code',
'&scope=', SPOCAuthorizer scope,
'&redirect_uri=', SPOCAuthorizer redirectUri,
'&state=', self auth randomState,
'&client_id=', SPOCAuthorizer clientId.
self assert: targetUrl = url.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'VE 6/20/2024 19:54'
}
SPOCTestAuthorizerProcess >> testCallbackEndpoint [

| response |
response := WebClient httpGet: SPOCAuthorizer redirectUri.
self assert: (response code = 404) not
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'VE 6/20/2024 19:54'
}
SPOCTestAuthorizerProcess >> testCallbackErrors [

| response |
response := WebClient httpGet: (SPOCAuthorizer redirectUri, '?code=123').
self assert: response code = 400.
response := WebClient httpGet: (SPOCAuthorizer redirectUri, '?state=123').
self assert: response code = 400.
response := WebClient httpGet: (SPOCAuthorizer redirectUri, '?error=error').
self assert: response code = 500
]

0 comments on commit cb55912

Please sign in to comment.