",
"slug":"cbcsrf",
@@ -27,10 +27,9 @@
"cbstorages":"^3.0.0"
},
"devDependencies":{
+ "commandbox-boxlang":"*",
"commandbox-cfformat":"*",
- "commandbox-docbox":"*",
- "commandbox-dotenv":"*",
- "commandbox-cfconfig":"*"
+ "commandbox-docbox":"*"
},
"ignore":[
"**/.*",
@@ -44,9 +43,15 @@
"build:module":"task run taskFile=build/Build.cfc :projectName=`package show slug` :version=`package show version`",
"build:docs":"task run taskFile=build/Build.cfc target=docs :projectName=`package show slug` :version=`package show version`",
"release":"recipe build/release.boxr",
- "format":"cfformat run handlers,models,test-harness/tests/specs/,ModuleConfig.cfc",
- "format:watch":"cfformat watch handlers,models,test-harness/tests/specs/,ModuleConfig.cfc",
- "format:check":"cfformat check handlers,models,test-harness/tests/specs/,ModuleConfig.cfc",
- "install:dependencies":"install && cd test-harness && install"
+ "format":"cfformat run handlers/,interceptors/,models/,test-harness/tests/specs,ModuleConfig.cfc --overwrite",
+ "format:watch":"cfformat watch handlers/,interceptors/,models/,test-harness/tests/specs,ModuleConfig.cfc ./.cfformat.json",
+ "format:check":"cfformat check handlers/,interceptors/,models/,test-harness/tests/specs,ModuleConfig.cfc",
+ "install:dependencies":"install && cd test-harness && install",
+ "start:lucee" : "server start serverConfigFile=server-lucee@5.json",
+ "start:2021" : "server start serverConfigFile=server-adobe@2021.json",
+ "stop:lucee" : "server stop serverConfigFile=server-lucee@5.json",
+ "stop:2021" : "server stop serverConfigFile=server-adobe@2021.json",
+ "logs:lucee" : "server log serverConfigFile=server-lucee@5.json --follow",
+ "logs:2021" : "server log serverConfigFile=server-adobe@2021.json --follow"
}
}
diff --git a/build/Build.cfc b/build/Build.cfc
index 926cce1..b15a671 100644
--- a/build/Build.cfc
+++ b/build/Build.cfc
@@ -12,6 +12,7 @@ component {
variables.cwd = getCWD().reReplace( "\.$", "" );
variables.artifactsDir = cwd & "/.artifacts";
variables.buildDir = cwd & "/.tmp";
+ variables.apidDocsDir = variables.buildDir & "/apidocs";
variables.apiDocsURL = "http://localhost:60299/apidocs/";
variables.testRunner = "http://localhost:60299/tests/runner.cfm";
@@ -31,7 +32,8 @@ component {
// Cleanup + Init Build Directories
[
variables.buildDir,
- variables.artifactsDir
+ variables.artifactsDir,
+ variables.apidDocsDir
].each( function( item ){
if ( directoryExists( item ) ) {
directoryDelete( item, true );
@@ -76,9 +78,6 @@ component {
// checksums
buildChecksums();
- // Build latest changelog
- latestChangelog();
-
// Finalize Message
print
.line()
@@ -130,9 +129,7 @@ component {
)
.toConsole();
- // Prepare exports directory
- variables.exportsDir = variables.artifactsDir & "/#projectName#/#arguments.version#";
- directoryCreate( variables.exportsDir, true, true );
+ ensureExportDir( argumentCollection = arguments );
// Project Build Dir
variables.projectBuildDir = variables.buildDir & "/#projectName#";
@@ -200,11 +197,12 @@ component {
version = "1.0.0",
outputDir = ".tmp/apidocs"
){
+ ensureExportDir( argumentCollection = arguments );
+
// Create project mapping
fileSystemUtil.createMapping( arguments.projectName, variables.cwd );
// Generate Docs
print.greenLine( "Generating API Docs, please wait..." ).toConsole();
- directoryCreate( arguments.outputDir, true, true );
command( "docbox generate" )
.params(
@@ -228,27 +226,6 @@ component {
);
}
- /**
- * Build the latest changelog file: changelog-latest.md
- */
- function latestChangelog(){
- print.blueLine( "Building latest changelog..." ).toConsole();
-
- if ( !fileExists( variables.cwd & "changelog.md" ) ) {
- return error( "Cannot continue building, changelog.md file doesn't exist!" );
- }
-
- fileWrite(
- variables.cwd & "changelog-latest.md",
- fileRead( variables.cwd & "changelog.md" ).split( "----" )[ 2 ].trim() & chr( 13 ) & chr( 10 )
- );
-
- print
- .greenLine( "Latest changelog file created at `changelog-latest.md`" )
- .line()
- .line( fileRead( variables.cwd & "changelog-latest.md" ) );
- }
-
/********************************************* PRIVATE HELPERS *********************************************/
/**
@@ -315,4 +292,18 @@ component {
return ( createObject( "java", "java.lang.System" ).getProperty( "cfml.cli.exitCode" ) ?: 0 );
}
+ /**
+ * Ensure the export directory exists at artifacts/NAME/VERSION/
+ */
+ private function ensureExportDir(
+ required projectName,
+ version = "1.0.0"
+ ){
+ if ( structKeyExists( variables, "exportsDir" ) && directoryExists( variables.exportsDir ) ){
+ return;
+ }
+ // Prepare exports directory
+ variables.exportsDir = variables.artifactsDir & "/#projectName#/#arguments.version#";
+ directoryCreate( variables.exportsDir, true, true );
+ }
}
diff --git a/build/release.boxr b/build/release.boxr
index e216f22..a63f2cc 100755
--- a/build/release.boxr
+++ b/build/release.boxr
@@ -7,19 +7,8 @@
# Merge development into it for release
!git merge --no-ff development
-# Tag the master repo with the version from box.json
-!git tag v`box package show version`
-
# Push all branches back out to github
!git push origin --all
-# Push all tags
-!git push origin --tags
-
# Check development again
!git checkout -f development
-
-# Bump to prepare for a new release, do minor, change if needed and don't tag
-bump --minor --!tagVersion
-!git commit -a -m "version bump"
-!git push origin development
\ No newline at end of file
diff --git a/changelog.md b/changelog.md
index 34998f9..a1a97bd 100644
--- a/changelog.md
+++ b/changelog.md
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
----
+## [Unreleased]
+
+### Added
+
+- BoxLang certification
+- Github Actions updates
+- ColdBox 7 Testing
+
## [3.1.0] => 2023-FEB-17
### Added
@@ -15,8 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Updates for Adobe 2021 server installations
-----
-
## [3.0.0] => 2022-OCT-10
### Added
@@ -27,24 +33,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Dropped ACF 2016
-----
-
## [2.3.1] => 2021-NOV-10
### Fixed
* Fixed cfformat locations on `box.json`
-----
-
## [2.3.0] => 2021-SEP-02
### Added/Compatiblity
* New setting: `enableAuthTokenRotator` which defaults to **false**, unlike previously which was **true**. This allows for rotation of keys for csrf tokens on login and logout if you are using cbauth via the new interceptor: `AuthRotator`. Make sure you turn this flag to **true** to keep the previous version functionality.
-----
-
## [2.2.0] => 2021-JUL-21
### Added
@@ -59,8 +59,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* ensure `actionMarkedToSkip()` returns `false` when the handler is empty
-----
-
## [2.1.0] => 2020-SEP-09
### Added
@@ -74,14 +72,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Null checks on `defaultValue` in case it's passed as an empty string
-----
-
## [2.0.1] => 2020-APR-06
* Deactivate the verifier by default
-----
-
## [2.0.0] => 2020-APR-02
### Features
@@ -100,23 +94,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* All methods signatures have changed, please see the readme for the updated methods
-----
-
## [1.1.0]
* Travis updates
* Build updates
* DocBox migration
-----
-
## [1.0.1]
* production ignore lists
* Unloading of helpers
-----
-
## [1.0.0]
* Create first module version
diff --git a/handlers/Main.cfc b/handlers/Main.cfc
index 9419400..ae389ca 100644
--- a/handlers/Main.cfc
+++ b/handlers/Main.cfc
@@ -2,7 +2,7 @@
* Handler to generate csrf tokens for a user according to key
* This handler is secured by default if using cbGuard or cbSecurity
*/
-component secured{
+component secured {
property name="settings" inject="coldbox:moduleSettings:cbcsrf";
@@ -19,4 +19,4 @@ component secured{
return csrfToken( rc.key ?: "default" );
}
-}
\ No newline at end of file
+}
diff --git a/interceptors/VerifyCsrf.cfc b/interceptors/VerifyCsrf.cfc
index dcd0718..9b28d6b 100644
--- a/interceptors/VerifyCsrf.cfc
+++ b/interceptors/VerifyCsrf.cfc
@@ -1,6 +1,6 @@
/**
-* Verifies the CSRF token on all non-GET requests
-*/
+ * Verifies the CSRF token on all non-GET requests
+ */
component extends="coldbox.system.Interceptor" accessors="true" {
/* *********************************************************************
@@ -8,13 +8,16 @@ component extends="coldbox.system.Interceptor" accessors="true" {
********************************************************************* */
property name="handlerService" inject="coldbox:handlerService";
- property name="cbcsrf" inject="@cbcsrf";
+ property name="cbcsrf" inject="@cbcsrf";
- /* *********************************************************************
- ** Properties
- ********************************************************************* */
+ /* *********************************************************************
+ ** Properties
+ ********************************************************************* */
- property name="isTestMode" type="boolean" default="false";
+ property
+ name ="isTestMode"
+ type ="boolean"
+ default="false";
/**
* Configure the interceptor
@@ -26,81 +29,83 @@ component extends="coldbox.system.Interceptor" accessors="true" {
/**
* Fire before event execution
*
- * @event
+ * @event
* @interceptData
- * @buffer
- * @rc
- * @prc
+ * @buffer
+ * @rc
+ * @prc
*/
- public void function preProcess( event, interceptData, rc, prc ) {
+ public void function preProcess( event, interceptData, rc, prc ){
// Are we in test mode? then skip
- if( variables.isTestMode ){
- if( log.canDebug() ){
+ if ( variables.isTestMode ) {
+ if ( log.canDebug() ) {
log.debug( "cbcsrf Verify skipped, we are in integration test mode" );
}
- return;
+ return;
}
// If it's a GET/HEAD/OPTIONS pass it
- if ( listFindNoCase( "GET,OPTIONS,HEAD", event.getHTTPMethod() ) ) {
- if( log.canDebug() ){
- log.debug( "cbcsrf Verify skipped due to HTTP method: #event.getHTTPMethod()#=>#event.getCurrentEvent()#" );
+ if ( listFindNoCase( "GET,OPTIONS,HEAD", event.getHTTPMethod() ) ) {
+ if ( log.canDebug() ) {
+ log.debug(
+ "cbcsrf Verify skipped due to HTTP method: #event.getHTTPMethod()#=>#event.getCurrentEvent()#"
+ );
}
- return;
+ return;
}
// is the incoming event is in the skipped events?
- if(
- variables.cbcsrf.getSettings()
+ if (
+ variables.cbcsrf
+ .getSettings()
.verifyExcludes
.filter( function( item ){
// If found, then don't return it
return !reFindNoCase( item, event.getCurrentEvent() );
- } ).len() != variables.cbcsrf.getSettings().verifyExcludes.len()
- ){
- if( log.canDebug() ){
- log.debug( "cbcsrf Verify skipped as event: #event.getCurrentEvent()# is in the verify excludes list." );
+ } )
+ .len() != variables.cbcsrf.getSettings().verifyExcludes.len()
+ ) {
+ if ( log.canDebug() ) {
+ log.debug(
+ "cbcsrf Verify skipped as event: #event.getCurrentEvent()# is in the verify excludes list."
+ );
}
return;
}
// Does the event have an annotation
- if ( actionMarkedToSkip( arguments.event ) ) {
- if( log.canDebug() ){
- log.debug( "cbcsrf Verify skipped as action has been annotated to skip: #event.getCurrentEvent()#" );
+ if ( actionMarkedToSkip( arguments.event ) ) {
+ if ( log.canDebug() ) {
+ log.debug(
+ "cbcsrf Verify skipped as action has been annotated to skip: #event.getCurrentEvent()#"
+ );
}
- return;
+ return;
}
// Do we have an incoming token in the form or header
- if ( ! event.valueExists( "csrf" ) && ! event.getHTTPHeader( "x-csrf-token", "" ).len() ) {
- throw(
- type = "TokenNotFoundException",
- message = "The CSRF token was not included."
- );
- }
+ if ( !event.valueExists( "csrf" ) && !event.getHTTPHeader( "x-csrf-token", "" ).len() ) {
+ throw( type = "TokenNotFoundException", message = "The CSRF token was not included." );
+ }
// Get it, put it in prc scope and Verify the token
prc.csrfToken = event.getValue( "csrf", event.getHTTPHeader( "x-csrf-token", "" ) );
- if ( ! variables.cbcsrf.verify( prc.csrfToken ) ) {
- throw(
- type = "TokenMismatchException",
- message = "The CSRF token is invalid."
- );
+ if ( !variables.cbcsrf.verify( prc.csrfToken ) ) {
+ throw( type = "TokenMismatchException", message = "The CSRF token is invalid." );
}
- if( log.canDebug() ){
+ if ( log.canDebug() ) {
log.debug( "cbcsrf verified for #event.getCurrentEvent()#" );
}
- }
+ }
/**
* Are we skipping the action or not due to the skipCsrf annotation?
*
- * @event
+ * @event
* @interceptData
*/
- private boolean function actionMarkedToSkip( required event ) {
+ private boolean function actionMarkedToSkip( required event ){
var handlerBean = handlerService.getHandlerBean( arguments.event.getCurrentEvent() );
if ( handlerBean.getHandler() == "" ) {
return false;
@@ -112,6 +117,6 @@ component extends="coldbox.system.Interceptor" accessors="true" {
}
return handlerBean.getActionMetadata( "skipCsrf", false );
- }
+ }
}
diff --git a/models/cbcsrf.cfc b/models/cbcsrf.cfc
index c428855..e08bffc 100644
--- a/models/cbcsrf.cfc
+++ b/models/cbcsrf.cfc
@@ -39,7 +39,7 @@ component accessors="true" singleton {
/**
* Provides a random token and stores it in cbstorages. You can also provide a specific key to store.
*
- * @key A random token is generated for the key provided.
+ * @key A random token is generated for the key provided.
* @forceNew If set to true, a new token is generated every time the function is called. If false, in case a token exists for the key, the same key is returned.
*
* @return The csrf token
@@ -91,14 +91,11 @@ component accessors="true" singleton {
* Validates the given token against the same stored in the session for a specific key.
*
* @token Token that to be validated against the token stored in the session.
- * @key The key against which the token be searched.
+ * @key The key against which the token be searched.
*
* @return If the token validated
*/
- public boolean function verify(
- required string token = "",
- string key
- ){
+ public boolean function verify( required string token = "", string key ){
var csrfData = cacheStorage.get( getTokenStorageKey(), {} );
// Mixins pass an empty key argument so "default" isn't set and verification fails when using the examples given in readme.md
@@ -133,15 +130,7 @@ component accessors="true" singleton {
var tokenBase = "#arguments.key##getRealIP()##randRange( 0, 65535, "SHA1PRNG" )##getTickCount()#";
// Return a 40 character hash as the new token
- return uCase(
- left(
- hash(
- tokenBase & variables.cacheStorage.getSessionKey(),
- "SHA-256"
- ),
- 40
- )
- );
+ return uCase( left( hash( tokenBase & variables.cacheStorage.getSessionKey(), "SHA-256" ), 40 ) );
}
/**
diff --git a/readme.md b/readme.md
index f125a7c..9f22483 100644
--- a/readme.md
+++ b/readme.md
@@ -1,10 +1,25 @@
-[](https://travis-ci.org/coldbox-modules/cbcsrf)
+
+
+
+
+
+
+
+
+
+ Copyright Since 2005 ColdBox Platform by Luis Majano and Ortus Solutions, Corp
+
+ www.coldbox.org |
+ www.ortussolutions.com
+
+
+----
# ColdBox Anti Cross Site Request Forgery Module (cbcsrf)
-A module that protects you against [CSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery) attacks by generating unique FORM/client tokens and providing your ColdBox application with new functions for verifying these tokens.
+A module that protects you against [CSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery) attacks by generating unique FORM/client tokens and providing your ColdBox application with new functions for verifying these tokens.
-Even though every CFML engine offers these functions natively, we have expanded them and have made them more flexible and more secure than the native CFML functions.
+Even though every engine offers these functions natively, we have expanded them and have made them more flexible and more secure than the native functions.
## Features
@@ -32,8 +47,9 @@ Apache License, Version 2.0.
## Requirements
+* BoxLang 1+
* Lucee 5+
-* ColdFusion 2016+
+* ColdFusion 2021+
## Installation
@@ -199,7 +215,7 @@ The verification process is as follows:
* If the incoming HTTP Method is a `get,options or head` skip verification
* If the incoming event matches any of the `verifyExcludes` setting, then skip verification
* If the action is marked with a `skipCsrf` annotation, then skip verification
-* If no `rc.csrf` exists and no `x-csrf-token` header exists, throw a
+* If no `rc.csrf` exists and no `x-csrf-token` header exists, throw a
`TokenNotFoundException` exception
* If the token is invalid then throw a `TokenMismatchException` exception
@@ -234,7 +250,7 @@ component{
This module also allows you to turn on the generation HTTP endpoint via the `enableEndpoint` boolean setting. When turned on the module will register the following route: `GET /cbcsrf/generate/:key?`. You can use this endpoint to generate tokens for your users via AJAX or UI only applications. Please note that you can pass an optional `/:key` URL parameter that will generate the token for that specific key.
-This endpoint should be secured, so we have annotated it with a `secured` annotation so if you are using `cbSecurity` or `cbGuard` this endpoint will only be available to logged in users.
+This endpoint should be secured, so we have annotated it with a `secured` annotation so if you are using `cbSecurity` or `cbGuard` this endpoint will only be available to logged in users.
********************************************************************************
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
@@ -249,7 +265,7 @@ Because of His grace, this project exists. If you don't like this, then don't re
By whom also we have access by faith into this grace wherein we stand, and rejoice in hope of the glory of God.
And not only so, but we glory in tribulations also: knowing that tribulation worketh patience;
And patience, experience; and experience, hope:
-And hope maketh not ashamed; because the love of God is shed abroad in our hearts by the
+And hope maketh not ashamed; because the love of God is shed abroad in our hearts by the
Holy Ghost which is given unto us. ." Romans 5:5
### THE DAILY BREAD
diff --git a/server-adobe@2021.json b/server-adobe@2021.json
index 2f2410a..77f7931 100644
--- a/server-adobe@2021.json
+++ b/server-adobe@2021.json
@@ -17,7 +17,8 @@
}
},
"jvm":{
- "heapSize":"1024"
+ "heapSize":"1024",
+ "javaVersion":"openjdk11_jre"
},
"openBrowser":"false",
"cfconfig":{
diff --git a/server-adobe@2023.json b/server-adobe@2023.json
new file mode 100644
index 0000000..64af56a
--- /dev/null
+++ b/server-adobe@2023.json
@@ -0,0 +1,29 @@
+{
+ "name":"cbcsrf-adobe@2023",
+ "app":{
+ "serverHomeDirectory":".engine/adobe2023",
+ "cfengine":"adobe@2023"
+ },
+ "web":{
+ "http":{
+ "port":"60299"
+ },
+ "rewrites":{
+ "enable":"true"
+ },
+ "webroot": "test-harness",
+ "aliases":{
+ "/moduleroot/cbcsrf":"../"
+ }
+ },
+ "jvm":{
+ "heapSize":"1024"
+ },
+ "openBrowser":"false",
+ "cfconfig": {
+ "file" : ".cfconfig.json"
+ },
+ "scripts" : {
+ "onServerInstall":"cfpm install zip,debugger,mysql"
+ }
+}
diff --git a/server-boxlang-cfml@1.json b/server-boxlang-cfml@1.json
new file mode 100644
index 0000000..482e6fe
--- /dev/null
+++ b/server-boxlang-cfml@1.json
@@ -0,0 +1,33 @@
+{
+ "name":"cbcsrf-boxlang@1",
+ "app":{
+ "serverHomeDirectory":".engine/boxlang",
+ "cfengine":"boxlang@be"
+ },
+ "web":{
+ "http":{
+ "port":"60299"
+ },
+ "rewrites":{
+ "enable":"true"
+ },
+ "webroot": "test-harness",
+ "aliases":{
+ "/moduleroot/cbcsrf":"../"
+ }
+ },
+ "JVM":{
+ "heapSize":"1024",
+ "javaVersion":"openjdk21_jre",
+ "args":"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8888"
+ },
+ "openBrowser":"false",
+ "cfconfig":{
+ "file":".cfconfig.json"
+ },
+ "env":{
+ },
+ "scripts":{
+ "onServerInitialInstall":"install bx-compat-cfml --noSave"
+ }
+}
diff --git a/server-adobe@2018.json b/server-lucee@6.json
similarity index 77%
rename from server-adobe@2018.json
rename to server-lucee@6.json
index 435c0d1..27ac8ac 100644
--- a/server-adobe@2018.json
+++ b/server-lucee@6.json
@@ -1,8 +1,8 @@
{
- "name":"cbcsrf-adobe@2018",
+ "name":"cbcsrf-lucee@6",
"app":{
- "serverHomeDirectory":".engine/adobe2018",
- "cfengine":"adobe@2018"
+ "serverHomeDirectory":".engine/lucee6",
+ "cfengine":"lucee@6"
},
"web":{
"http":{
diff --git a/test-harness/box.json b/test-harness/box.json
index a269a2f..0106138 100644
--- a/test-harness/box.json
+++ b/test-harness/box.json
@@ -7,7 +7,7 @@
"dependencies":{
"coldbox":"^6.0.0",
"testbox":"*",
- "cbstorages":"^2.0.0"
+ "cbstorages":"^3.0.0"
},
"devDependencies":{},
"installPaths":{
@@ -23,4 +23,4 @@
"cfpm:install":"echo '\".engine/adobe2021/WEB-INF/cfusion/bin/cfpm.sh\" install ${1}' | run",
"install:2021":"run-script cfpm:install zip"
}
-}
\ No newline at end of file
+}
diff --git a/test-harness/tests/Application.cfc b/test-harness/tests/Application.cfc
index e9d01c9..ccf0069 100644
--- a/test-harness/tests/Application.cfc
+++ b/test-harness/tests/Application.cfc
@@ -52,7 +52,7 @@ component {
// If hitting the runner or specs, prep our virtual app
if ( getBaseTemplatePath().replace( expandPath( "/tests" ), "" ).reFindNoCase( "(runner|specs)" ) ) {
- request.coldBoxVirtualApp.startup();
+ request.coldBoxVirtualApp.startup( true );
}
return true;
diff --git a/test-harness/tests/specs/csrfSpec.cfc b/test-harness/tests/specs/csrfSpec.cfc
index 0105772..f0ee57b 100644
--- a/test-harness/tests/specs/csrfSpec.cfc
+++ b/test-harness/tests/specs/csrfSpec.cfc
@@ -1,27 +1,26 @@
/**
-* My BDD Test
-*/
-component extends="coldbox.system.testing.BaseTestCase" appMapping="/root"{
+ * My BDD Test
+ */
+component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
function run(){
// all your suites go here.
describe( "CSRF Module", function(){
-
- beforeEach(function( currentSpec ){
- csrf = getInstance( "@cbcsrf" );
+ beforeEach( function( currentSpec ){
+ csrf = getInstance( "@cbcsrf" );
cacheStorage = getInstance( "cacheStorage@cbcsrf" );
csrf.rotate();
setup();
- });
+ } );
it( "should register components", function(){
- expect( csrf ).toBeComponent();
- });
+ expect( csrf ).toBeComponent();
+ } );
it( "should run all integration points", function(){
- var event = execute( event="main.index", renderResults=true );
+ var event = execute( event = "main.index", renderResults = true );
expect( event.getValue( "cbox_rendered_content" ) ).toMatch( "Verified: true" );
- });
+ } );
it( "can generate and verify different tokens for different keys", function(){
var token1 = csrf.generate();
@@ -30,9 +29,8 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root"{
expect( token1 ).notToBe( token2 );
expect( csrf.verify( token1 ) ).toBeTrue();
expect( csrf.verify( token2, "unitTest" ) ).toBeTrue();
- });
-
- });
+ } );
+ } );
}
}
diff --git a/test-harness/tests/specs/csrfVerifierSpec.cfc b/test-harness/tests/specs/csrfVerifierSpec.cfc
index 5374241..d081777 100644
--- a/test-harness/tests/specs/csrfVerifierSpec.cfc
+++ b/test-harness/tests/specs/csrfVerifierSpec.cfc
@@ -1,70 +1,77 @@
/**
-* My BDD Test
-*/
-component extends="coldbox.system.testing.BaseTestCase" appMapping="/root"{
+ * My BDD Test
+ */
+component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
function run(){
// all your suites go here.
describe( "Verify Interceptor", function(){
-
- beforeEach(function( currentSpec ){
+ beforeEach( function( currentSpec ){
setup();
- csrf = getInstance( "@cbcsrf" );
- event = prepareMock( getRequestContext() );
- verifier = prepareMock( getInstance( dsl="coldbox:interceptor:VerifyCsfr@cbcsrf" ) );
+ csrf = getInstance( "@cbcsrf" );
+ event = prepareMock( getRequestContext() );
+ verifier = prepareMock( getInstance( dsl = "coldbox:interceptor:VerifyCsfr@cbcsrf" ) );
verifier.setIsTestMode( false );
- });
+ } );
it( "should be loaded", function(){
expect( verifier ).toBeComponent();
- });
+ } );
it( "should not verify if the method is in GET/OPTIONS/HEAD", function(){
- var logger = prepareMock( verifier.getLog() )
- .$( "canDebug", true )
- .$( "debug" );
- event
- .$( "getHTTPMethod", "OPTIONS" )
- .$( "getCurrentEvent", "hello.save" );
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
+ var logger = prepareMock( verifier.getLog() ).$( "canDebug", true ).$( "debug" );
+ event.$( "getHTTPMethod", "OPTIONS" ).$( "getCurrentEvent", "hello.save" );
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
expect( logger.$callLog().debug[ 1 ][ 1 ] ).toInclude( "cbcsrf Verify skipped due to HTTP method" );
} );
it( "should not verify if the method is in the excludes list", function(){
- var logger = prepareMock( verifier.getLog() )
- .$( "canDebug", true )
- .$( "debug" );
- event
- .$( "getHTTPMethod", "POST" )
- .$( "getCurrentEvent", "cbtest.index" );
-
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
+ var logger = prepareMock( verifier.getLog() ).$( "canDebug", true ).$( "debug" );
+ event.$( "getHTTPMethod", "POST" ).$( "getCurrentEvent", "cbtest.index" );
+
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
expect( logger.$callLog().debug[ 1 ][ 1 ] ).toInclude( "cbcsrf Verify skipped as event:" );
} );
it( "should not verify if the action is marked for skipping", function(){
- var logger = prepareMock( verifier.getLog() )
- .$( "canDebug", true )
- .$( "debug" );
- event
- .$( "getHTTPMethod", "POST" )
- .$( "getCurrentEvent", "verify.index" );
+ var logger = prepareMock( verifier.getLog() ).$( "canDebug", true ).$( "debug" );
+ event.$( "getHTTPMethod", "POST" ).$( "getCurrentEvent", "verify.index" );
verifier.$( "actionMarkedToSkip", true );
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
- expect( logger.$callLog().debug[ 1 ][ 1 ] ).toInclude( "cbcsrf Verify skipped as action has been annotated to skip" );
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
+ expect( logger.$callLog().debug[ 1 ][ 1 ] ).toInclude(
+ "cbcsrf Verify skipped as action has been annotated to skip"
+ );
} );
it( "should throw an exception if the token is not passed", function(){
- event
- .$( "getHTTPMethod", "POST" )
- .$( "getCurrentEvent", "verify.index" );
+ event.$( "getHTTPMethod", "POST" ).$( "getCurrentEvent", "verify.index" );
verifier.$( "actionMarkedToSkip", false );
expect( function(){
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
} ).toThrow( "TokenNotFoundException" );
- });
+ } );
it( "should invalidate if the token is invalid via the rc", function(){
event
@@ -74,51 +81,70 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root"{
verifier.$( "actionMarkedToSkip", false );
expect( function(){
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
} ).toThrow( "TokenMismatchException" );
- });
+ } );
it( "should invalidate if the token is invalid via the header", function(){
event
.$( "getHTTPMethod", "POST" )
.$( "getCurrentEvent", "verify.index" )
- .$( "getHttpHeader" ).$args( "x-csrf-token", "" ).$results( "456" );
+ .$( "getHttpHeader" )
+ .$args( "x-csrf-token", "" )
+ .$results( "456" );
verifier.$( "actionMarkedToSkip", false );
expect( function(){
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
} ).toThrow( "TokenMismatchException" );
- });
+ } );
it( "should validate if the token is valid via the rc", function(){
- var logger = prepareMock( verifier.getLog() )
- .$( "canDebug", true )
- .$( "debug" );
+ var logger = prepareMock( verifier.getLog() ).$( "canDebug", true ).$( "debug" );
event
.$( "getHTTPMethod", "POST" )
.$( "getCurrentEvent", "verify.index" )
.setValue( "csrf", csrf.generate() );
verifier.$( "actionMarkedToSkip", false );
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
expect( logger.$callLog().debug[ 1 ][ 1 ] ).toInclude( "cbcsrf verified for" );
- });
+ } );
it( "should validate if the token is valid via the header", function(){
- var logger = prepareMock( verifier.getLog() )
- .$( "canDebug", true )
- .$( "debug" );
+ var logger = prepareMock( verifier.getLog() ).$( "canDebug", true ).$( "debug" );
event
.$( "getHTTPMethod", "POST" )
.$( "getCurrentEvent", "verify.index" )
- .$( "getHttpHeader" ).$args( "x-csrf-token", "" ).$results( csrf.generate() );
+ .$( "getHttpHeader" )
+ .$args( "x-csrf-token", "" )
+ .$results( csrf.generate() );
verifier.$( "actionMarkedToSkip", false );
- verifier.preProcess( event, {}, event.getCollection(), event.getPrivateCollection() );
+ verifier.preProcess(
+ event,
+ {},
+ event.getCollection(),
+ event.getPrivateCollection()
+ );
expect( logger.$callLog().debug[ 1 ][ 1 ] ).toInclude( "cbcsrf verified for" );
- });
-
- });
+ } );
+ } );
}
-}
\ No newline at end of file
+}