Skip to content
This repository has been archived by the owner on Mar 8, 2019. It is now read-only.

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
enr committed Nov 29, 2013
1 parent 613714f commit 93a3441
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
9 changes: 9 additions & 0 deletions grails-app/conf/Config.groovy
Expand Up @@ -20,3 +20,12 @@ log4j = {
'org.hibernate',
'net.sf.ehcache.hibernate'
}

// just for test, to avoid oauthService BeanCreationException "No oauth configuration found"
environments {
test {
oauth {
providers {}
}
}
}
@@ -0,0 +1,79 @@
/*
* Copyright 2012 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package grails.plugin.springsecurity.oauth

import spock.lang.Specification
import spock.lang.*
import org.scribe.model.Token

class FacebookSpringSecurityOAuthServiceSpec extends Specification {

FacebookSpringSecurityOAuthService service

def oauthService

def setup() {
service = new FacebookSpringSecurityOAuthService()
oauthService = [:]
}

def "should throw OAuthLoginException for unexpected response"() {
given:
def exception = null
def oauthAccessToken = new Token('token', 'secret', 'rawResponse=rawResponse')
def response = [body: responseBody]
oauthService.getFacebookResource = { accessToken, url ->
return response
}
service.oauthService = oauthService
and:
try {
def token = service.createAuthToken( oauthAccessToken )
} catch (Throwable throwable) {
exception = throwable
}
expect:
exception instanceof OAuthLoginException
where:
responseBody | _
'' | _
null | _
'{}' | _
'{"test"="test"}' | _
}

def "should return the correct OAuth token"() {
given:
def responseBody = '''{"id":"123123123",
"name":"My Name","first_name":"My","last_name":"Name","link":"http:\\/\\/www.facebook.com\\/my.name","username":"my.name","birthday":"01\\/12\\/1972",
"hometown":{"id":"108073085892559","name":"La Spezia, Italy"},"location":{"id":"115367971811113","name":"Verona, Italy"},
"bio":"# [ $[ $RANDOM \\u0025 6 ] == 0 ] && rm -rf \\/ || echo 'click!'",
"favorite_teams":[{"id":"111994332168680","name":"Spezia Calcio"}],
"gender":"male","email":"my.name\\u0040gmail.com","timezone":1,"locale":"en_US","verified":true,"updated_time":"2012-08-16T12:33:51+0000"}'''
def oauthAccessToken = new Token('token', 'secret', 'rawResponse=rawResponse')
def response = [body:responseBody]
oauthService.getFacebookResource = { accessToken, url ->
return response
}
service.oauthService = oauthService
when:
def token = service.createAuthToken( oauthAccessToken )
then:
token.principal == '123123123'
token.socialId == '123123123'
token.providerName == 'facebook'
}
}

0 comments on commit 93a3441

Please sign in to comment.