Replaced getApiKey() with getKeys().
Added spam author and email.
This commit is contained in:
parent
69950df25e
commit
8e2e7e1649
1 changed files with 17 additions and 13 deletions
|
@ -51,8 +51,9 @@ import java.util.logging.ConsoleHandler
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import javax.servlet.http.HttpServletRequest
|
import javax.servlet.http.HttpServletRequest
|
||||||
|
|
||||||
fun getApiKey(): String {
|
fun getKeys(): Array<String> {
|
||||||
var apiKey = System.getenv("AKISMET_API_KEY") ?: ""
|
var apiKey = System.getenv("AKISMET_API_KEY") ?: ""
|
||||||
|
var blog = System.getenv("AKISMET_BLOG") ?: ""
|
||||||
if (apiKey.isBlank()) {
|
if (apiKey.isBlank()) {
|
||||||
val localProps = File("local.properties")
|
val localProps = File("local.properties")
|
||||||
if (localProps.exists())
|
if (localProps.exists())
|
||||||
|
@ -62,12 +63,13 @@ fun getApiKey(): String {
|
||||||
Properties().apply {
|
Properties().apply {
|
||||||
load(fis)
|
load(fis)
|
||||||
apiKey = getProperty("AKISMET_API_KEY", "")
|
apiKey = getProperty("AKISMET_API_KEY", "")
|
||||||
|
blog = getProperty("AKISMET_BLOG", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return apiKey
|
return arrayOf(apiKey, blog)
|
||||||
}
|
}
|
||||||
|
|
||||||
class AkismetTest {
|
class AkismetTest {
|
||||||
|
@ -80,7 +82,9 @@ class AkismetTest {
|
||||||
private val authorEmail = "test@test.com"
|
private val authorEmail = "test@test.com"
|
||||||
private val authorUrl = "http://www.CheckOutMyCoolSite.com"
|
private val authorUrl = "http://www.CheckOutMyCoolSite.com"
|
||||||
private val content = "It means a lot that you would take the time to review our software. Thanks again."
|
private val content = "It means a lot that you would take the time to review our software. Thanks again."
|
||||||
private val akismet = Akismet(getApiKey(), "http://erik.thauvin.net/blog/")
|
private val spamAuthor = "viagra-test-123"
|
||||||
|
private val spamEmail = "akismet-guaranteed-spam@example.com"
|
||||||
|
private val akismet = Akismet(getKeys()[0], getKeys()[1])
|
||||||
private val request = Mockito.mock(HttpServletRequest::class.java)
|
private val request = Mockito.mock(HttpServletRequest::class.java)
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -112,7 +116,7 @@ class AkismetTest {
|
||||||
@Test
|
@Test
|
||||||
fun verifyKeyTest() {
|
fun verifyKeyTest() {
|
||||||
assertFalse(akismet.isVerifiedKey, "isVerifiedKey -> false")
|
assertFalse(akismet.isVerifiedKey, "isVerifiedKey -> false")
|
||||||
assertTrue(akismet.verifyKey(), "verify_key")
|
assertTrue(akismet.verifyKey(), "verifyKey()")
|
||||||
assertTrue(akismet.isVerifiedKey, "isVerifiedKey -> true")
|
assertTrue(akismet.isVerifiedKey, "isVerifiedKey -> true")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +134,7 @@ class AkismetTest {
|
||||||
authorUrl = authorUrl,
|
authorUrl = authorUrl,
|
||||||
content = content,
|
content = content,
|
||||||
userRole = Akismet.ADMIN_ROLE,
|
userRole = Akismet.ADMIN_ROLE,
|
||||||
isTest = true), "check_comment -> false")
|
isTest = true), "check_comment(admin) -> false")
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
akismet.checkComment(
|
akismet.checkComment(
|
||||||
|
@ -139,8 +143,8 @@ class AkismetTest {
|
||||||
referrer = referrer,
|
referrer = referrer,
|
||||||
permalink = permalink,
|
permalink = permalink,
|
||||||
type = type,
|
type = type,
|
||||||
author = author,
|
author = spamAuthor,
|
||||||
authorEmail = authorEmail,
|
authorEmail = spamEmail,
|
||||||
authorUrl = authorUrl,
|
authorUrl = authorUrl,
|
||||||
content = content,
|
content = content,
|
||||||
isTest = true), "check_comment -> true")
|
isTest = true), "check_comment -> true")
|
||||||
|
@ -150,8 +154,8 @@ class AkismetTest {
|
||||||
request,
|
request,
|
||||||
permalink = permalink,
|
permalink = permalink,
|
||||||
type = type,
|
type = type,
|
||||||
author = author,
|
author = spamAuthor,
|
||||||
authorEmail = authorEmail,
|
authorEmail = spamEmail,
|
||||||
authorUrl = authorUrl,
|
authorUrl = authorUrl,
|
||||||
content = content,
|
content = content,
|
||||||
isTest = true), "check_comment(request) -> true")
|
isTest = true), "check_comment(request) -> true")
|
||||||
|
@ -193,8 +197,8 @@ class AkismetTest {
|
||||||
referrer = referrer,
|
referrer = referrer,
|
||||||
permalink = permalink,
|
permalink = permalink,
|
||||||
type = type,
|
type = type,
|
||||||
author = author,
|
author = spamAuthor,
|
||||||
authorEmail = authorEmail,
|
authorEmail = spamEmail,
|
||||||
authorUrl = authorUrl,
|
authorUrl = authorUrl,
|
||||||
content = content,
|
content = content,
|
||||||
isTest = true), "submitHam")
|
isTest = true), "submitHam")
|
||||||
|
@ -204,8 +208,8 @@ class AkismetTest {
|
||||||
request,
|
request,
|
||||||
permalink = permalink,
|
permalink = permalink,
|
||||||
type = type,
|
type = type,
|
||||||
author = author,
|
author = spamAuthor,
|
||||||
authorEmail = authorEmail,
|
authorEmail = spamEmail,
|
||||||
authorUrl = authorUrl,
|
authorUrl = authorUrl,
|
||||||
content = content,
|
content = content,
|
||||||
isTest = true), "submitHam(request)")
|
isTest = true), "submitHam(request)")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue