Skip to content
This repository has been archived by the owner on Jul 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #192 from osiam/osng-487
Browse files Browse the repository at this point in the history
add test for the extensiontype interface
  • Loading branch information
dacrome committed Oct 1, 2014
2 parents 93f186f + fb0d1bb commit b5f1941
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 34 deletions.
68 changes: 35 additions & 33 deletions src/test/groovy/org/osiam/test/integration/ControllerIT.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ class ControllerIT extends AbstractIT {
assert responseContentType == expectedResponseType

where:
testCase | requestPath | contentType | expectedResponseCode | expectedResponseType
"a" | "/Users" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"b" | "/Users/" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"c" | "/Groups" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"d" | "/Groups/" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"e" | "/Users" | ContentType.ANY | 200 | "application/json;charset=UTF-8"
"f" | "/Users" | ContentType.TEXT | 406 | null
"g" | "/Users" | ContentType.BINARY | 406 | null
"h" | "/Users" | ContentType.HTML | 406 | null
"i" | "/Users" | ContentType.URLENC | 406 | null
"j" | "/Users" | ContentType.XML | 406 | null
"k" | "/Users" | "invalid" | 406 | null
"l" | "/Users" | "/" | 406 | null
"m" | "/Metrics" | ContentType.JSON | 200 | "application/json; charset=UTF-8"
"n" | "/Metrics/" | ContentType.JSON | 200 | "application/json; charset=UTF-8"
testCase | requestPath | contentType | expectedResponseCode | expectedResponseType
"a" | "/Users" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"b" | "/Users/" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"c" | "/Groups" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"d" | "/Groups/" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"e" | "/Users" | ContentType.ANY | 200 | "application/json;charset=UTF-8"
"f" | "/Users" | ContentType.TEXT | 406 | null
"g" | "/Users" | ContentType.BINARY | 406 | null
"h" | "/Users" | ContentType.HTML | 406 | null
"i" | "/Users" | ContentType.URLENC | 406 | null
"j" | "/Users" | ContentType.XML | 406 | null
"k" | "/Users" | "invalid" | 406 | null
"l" | "/Users" | "/" | 406 | null
"m" | "/Metrics" | ContentType.JSON | 200 | "application/json; charset=UTF-8"
"n" | "/Metrics/" | ContentType.JSON | 200 | "application/json; charset=UTF-8"
"o" | "/osiam/extension-definition" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
"p" | "/osiam/extension-definition/" | ContentType.JSON | 200 | "application/json;charset=UTF-8"
}

@Unroll
Expand Down Expand Up @@ -249,72 +251,72 @@ class ControllerIT extends AbstractIT {
responseStatusCode == 200
responseContent.Resources[0].userName == 'marissa'
}

def 'OSNG-444: A request to revoke a valid token should invalidate the token'() {

given: 'a valid access token'
AccessToken accessToken = osiamConnectorForClientCredentialsGrant.retrieveAccessToken()

when: 'a token revocation is performed'
AccessToken validationResult = osiamConnector.validateAccessToken(accessToken)
osiamConnector.revokeAccessToken(accessToken)
osiamConnector.validateAccessToken(accessToken) // authorization should now be invalid

then: 'the token should be revoked'
validationResult.expired==false
thrown(UnauthorizedException)
}

def 'OSNG-444: A request to revoke an invalid token is not authorized'() {

given: 'an invalid access token'
AccessToken accessToken = new AccessToken.Builder("invalid").build()

when: 'a token revocation is performed'
osiamConnector.revokeAccessToken(accessToken)

then: 'the request is not authorized'
thrown(UnauthorizedException)
}

def 'OSNG-444: Subsequent requests to revoke a valid token should not be authorized'() {

given: 'a valid access token'
AccessToken accessToken = osiamConnectorForClientCredentialsGrant.retrieveAccessToken()

when: 'multiple token revocations are performed'
AccessToken validationResult = osiamConnector.validateAccessToken(accessToken)
osiamConnector.revokeAccessToken(accessToken)
osiamConnector.revokeAccessToken(accessToken)

then: 'subsequent requests are not authorized'
thrown(UnauthorizedException)
}

def 'OSNG-467: A request to revoke access tokens of a given user should invalidate his token'() {
given: 'a valid access token'
def userId = "cef9452e-00a9-4cec-a086-d171374ffbef"
AccessToken serviceAccessToken = osiamConnectorForClientCredentialsGrant.retrieveAccessToken()

when: 'a token revocation is performed'
AccessToken validationResult = osiamConnector.validateAccessToken(accessToken)
osiamConnector.revokeAllAccessTokens(userId, serviceAccessToken)
validationResult = osiamConnector.validateAccessToken(accessToken)

then: 'the tokens should be invalid'
validationResult.expired==false
thrown(UnauthorizedException)
}

def 'OSNG-467: Repeating requests to revoke access tokens of a given user should not have negative effect'() {
given: 'valid access tokens'
def userId = "cef9452e-00a9-4cec-a086-d171374ffbef"
AccessToken serviceAccessToken = osiamConnectorForClientCredentialsGrant.retrieveAccessToken()

when: 'multiple token revocations are performed'
osiamConnector.revokeAllAccessTokens(userId, serviceAccessToken)
osiamConnector.revokeAllAccessTokens(userId, serviceAccessToken)

then: 'nothing should happen'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

package org.osiam.test.integration

import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method

import org.osiam.client.oauth.Scope
import org.osiam.client.exception.ConflictException
import org.osiam.resources.scim.Extension
import org.osiam.resources.scim.User
Expand Down Expand Up @@ -82,4 +86,63 @@ class ScimExtensionTypesIT extends AbstractExtensionBaseIT {
FIELD_NAME_REFERENCE | FIELD_TYPE_REFERENCE | STRING_VALUE
}

}
def 'URI: /osiam/extension-definition will return all persisted extension definitions'() {
given:
def accessToken = osiamConnector.retrieveAccessToken("marissa", "koala", Scope.ALL)
def statusCode
def jsonContent

when:
def httpClient = new HTTPBuilder(RESOURCE_ENDPOINT)

httpClient.request(Method.GET) { req ->
uri.path = RESOURCE_ENDPOINT + '/osiam/extension-definition'
headers.'Authorization' = 'Bearer ' + accessToken.getToken()

response.success = { resp, json ->
statusCode = resp.statusLine.statusCode
jsonContent = json
}

response.failure = { resp ->
statusCode = resp.statusLine.statusCode
}
}

then:
statusCode == 200
jsonContent[0].urn == 'extension'
jsonContent[0].namedTypePairs.birthday == 'DATE_TIME'
jsonContent[0].namedTypePairs.weight == 'DECIMAL'
jsonContent[0].namedTypePairs.mother == 'REFERENCE'
jsonContent[0].namedTypePairs.newsletter == 'BOOLEAN'
jsonContent[0].namedTypePairs.age == 'INTEGER'
jsonContent[0].namedTypePairs.gender == 'STRING'
jsonContent[0].namedTypePairs.photo == 'BINARY'
}

def 'URI: /osiam/extension-definition needs an authentication'() {
given:
def statusCode

when:
def httpClient = new HTTPBuilder(RESOURCE_ENDPOINT)

httpClient.request(Method.GET) { req ->
uri.path = RESOURCE_ENDPOINT + '/osiam/extension-definition'
headers.'Authorization' = 'Bearer NOT-VALID'

response.success = { resp, json ->
statusCode = resp.statusLine.statusCode
jsonContent = json
}

response.failure = { resp ->
statusCode = resp.statusLine.statusCode
}
}

then:
statusCode == 401
}
}

0 comments on commit b5f1941

Please sign in to comment.