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

Commit

Permalink
Merge pull request #35 from iamthechad/34-rework-api
Browse files Browse the repository at this point in the history
Remove ‘noscript’ support
  • Loading branch information
iamthechad committed Feb 24, 2019
2 parents d757cf3 + 1fe2b9b commit 38e7338
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 64 deletions.
7 changes: 3 additions & 4 deletions README.md
Expand Up @@ -47,7 +47,7 @@ This plugin is designed to make using the ReCaptcha service within Grails 3 easy

Add the following to your `build.gradle`

compile "org.grails.plugins:recaptcha:3.2.0"
compile "org.grails.plugins:recaptcha:4.0.0"

## Configuration
Add the following to your application's `application.yml` file:
Expand All @@ -56,8 +56,7 @@ Add the following to your application's `application.yml` file:
publicKey: "your public key"
privateKey: "your private key"
includeScript: true
includeNoScript: true

These configurations can also be placed at environment-specific locations in the configuration:

environments:
Expand Down Expand Up @@ -296,6 +295,6 @@ See the [contribution guidelines](./CONTRIBUTING.md).

# Suggestions or Comments

Feel free to submit questions through GitHub or to StackOverflow.
Feel free to submit questions through GitHub.

Alternatively you can contact me directly - cjohnston at megatome dot com
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -15,7 +15,7 @@ plugins {
id 'com.jfrog.artifactory' version '4.4.0'
}

version "3.3.0-SNAPSHOT"
version "4.0.0-SNAPSHOT"
group "org.grails.plugins"

apply plugin: 'eclipse'
Expand Down
Expand Up @@ -70,7 +70,6 @@ class RecaptchaService {
recap = new ReCaptcha(
publicKey: config.publicKey,
privateKey: config.privateKey,
includeNoScript: safeGetConfigValue('includeNoScript', true),
includeScript: safeGetConfigValue('includeScript', true),
timeoutConfig: config.timeoutConfig,
proxy: proxy)
Expand Down
32 changes: 0 additions & 32 deletions src/main/groovy/com/megatome/grails/recaptcha/ReCaptcha.groovy
Expand Up @@ -31,7 +31,6 @@ public class ReCaptcha {

String publicKey
String privateKey
Boolean includeNoScript = false
Boolean includeScript = true

def timeoutConfig
Expand Down Expand Up @@ -64,10 +63,6 @@ public class ReCaptcha {
}
message << "></div>\r\n"

if (includeNoScript) {
message << buildNoScript(publicKey)
}

return message.toString()
}

Expand All @@ -82,10 +77,6 @@ public class ReCaptcha {

message << createScriptTagExplicit(options)

if (includeNoScript) {
message << buildNoScript(publicKey)
}

return message.toString()
}

Expand Down Expand Up @@ -139,29 +130,6 @@ public class ReCaptcha {
return "<script src=\"${JS_URL}?${qs.toString()}\" async defer></script>"
}

private static String buildNoScript(key) {
return """<noscript>
<div style=\"width: 302px; height: 352px;\">
<div style=\"width: 302px; height: 352px; position: relative;\">
<div style=\"width: 302px; height: 352px; position: absolute;\">
<iframe src=\"$BASE_URL/fallback?k=$key\"
frameborder=\"0\" scrolling=\"no\"
style=\"width: 302px; height:352px; border-style: none;\">
</iframe>
</div>
<div style=\"width: 250px; height: 80px; position: absolute; border-style: none;
bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;\">
<textarea id=\"g-recaptcha-response\" name=\"g-recaptcha-response\"
class=\"g-recaptcha-response\"
style=\"width: 250px; height: 80px; border: 1px solid #c1c1c1;
margin: 0px; padding: 0px; resize: none;\" value=\"\">
</textarea>
</div>
</div>
</div>
</noscript>"""
}

/**
* Validates a reCaptcha challenge and response.
*
Expand Down
3 changes: 0 additions & 3 deletions src/main/templates/RecaptchaConfig.groovy
Expand Up @@ -3,9 +3,6 @@ recaptcha {
publicKey = ""
privateKey = ""

// Include the noscript tags in the generated captcha
includeNoScript = true

// Include the required script tag with the generated captcha
includeScript = true
}
Expand Down
Expand Up @@ -67,23 +67,20 @@ class RecaptchaServiceTests extends Specification {
setup:
config.recaptcha.publicKey = "ABC"
config.recaptcha.privateKey = "123"
config.recaptcha.includeNoScript = true

when:
def response = service.createCaptcha([:])

then:
response.contains("\"g-recaptcha\"")
response.contains("data-sitekey=\"ABC\"")
response.contains("<noscript>")

when:
response = service.createCaptcha(theme:"dark", lang:"fr", type:"audio", size: "normal", successCallback: "successCB", expiredCallback: "expiredCB", tabindex: 1, includeScript: true)

then:
response.contains("\"g-recaptcha\"")
response.contains("data-sitekey=\"ABC\"")
response.contains("<noscript>")
response.contains("data-theme=\"dark\"")
response.contains("data-type=\"audio\"")
response.contains("data-size=\"normal\"")
Expand All @@ -108,7 +105,6 @@ class RecaptchaServiceTests extends Specification {
then:
response.contains("\"g-recaptcha\"")
response.contains("data-sitekey=\"ABC\"")
response.contains("<noscript>")
}

void "test create explicit captcha"() {
Expand All @@ -123,7 +119,6 @@ class RecaptchaServiceTests extends Specification {
response.contains("loadCB")
!response.contains("\"g-recaptcha\"")
!response.contains("data-sitekey=\"ABC\"")
response.contains("<noscript>")
}

void "test create render parameters"() {
Expand Down
Expand Up @@ -23,10 +23,10 @@ import spock.lang.Specification
*/

class ReCaptchaTests extends Specification {
private ReCaptcha r;
private ReCaptcha r

def setup() {
r = new ReCaptcha(privateKey: "testing", publicKey: "testing", includeNoScript: false)
r = new ReCaptcha(privateKey: "testing", publicKey: "testing")
}

def "Create captcha with various script options"() {
Expand All @@ -42,12 +42,6 @@ class ReCaptchaTests extends Specification {

then:"Script tag should be emitted as part of the captcha"
r.createRecaptchaHtml(includeScript: true).contains("<script")

when:"includeNoScript is true"
r.includeNoScript = true

then:"noscript tag should be emitted as part of the captcha"
r.createRecaptchaHtml(null).contains("<noscript>")
}

def "Create captcha with options"() {
Expand Down Expand Up @@ -103,12 +97,6 @@ class ReCaptchaTests extends Specification {
def "Create explicit captcha"() {
expect:
buildAndCheckExplicitHTML(loadCallback: "foo")

when:
r.includeNoScript = true

then:
buildAndCheckExplicitHTML(loadCallback: "foo", true)
}

def "Create explicit captcha with no callback"() {
Expand Down Expand Up @@ -218,7 +206,7 @@ class ReCaptchaTests extends Specification {
}
}

private void buildAndCheckExplicitHTML(Map options, includeNoScript = false) {
private void buildAndCheckExplicitHTML(Map options) {
def expectedLang = null
if (options.lang) {
expectedLang = options.lang
Expand All @@ -231,8 +219,5 @@ class ReCaptchaTests extends Specification {
assert !html.contains("hl=")
}
assert html.contains("onload=" + options.loadCallback)
if (includeNoScript) {
assert html.contains("<noscript>")
}
}
}

0 comments on commit 38e7338

Please sign in to comment.