Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
backbone-adapter-javascript
Commits
73605335
Unverified
Commit
73605335
authored
2 years ago
by
Dan Jones
Browse files
Options
Download
Email Patches
Plain Diff
test: add tests for token handling
+ getAuthorizationHeader + tokenValid
parent
bb722d6b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
2 deletions
+84
-2
features/adapter_get-authorization-header.feature
features/adapter_get-authorization-header.feature
+21
-0
features/adapter_token-valid.feature
features/adapter_token-valid.feature
+21
-0
test/cucumber/adapter/broadcast.steps.js
test/cucumber/adapter/broadcast.steps.js
+1
-2
test/cucumber/adapter/common.steps.js
test/cucumber/adapter/common.steps.js
+0
-0
test/cucumber/adapter/get-authorization-header.steps.js
test/cucumber/adapter/get-authorization-header.steps.js
+15
-0
test/cucumber/adapter/token-valid.steps.js
test/cucumber/adapter/token-valid.steps.js
+26
-0
No files found.
features/adapter_get-authorization-header.feature
0 → 100644
View file @
73605335
Feature
:
Does the adapter authenticate?
When an adapter instance is created it authenticates and receives a token
Scenario
:
getAuthorizationHeader returns a bearer token
Given
valid config
When
the adapter instance is created
When
the auth method is called
When
the getAuthorizationHeader method is called
Then
a headers object is returned containing a bearer token authorization header
Scenario
:
getAuthorizationHeader implicitly calls auth if required
Given
valid config
When
the adapter instance is created
When
the getAuthorizationHeader method is called
Then
a headers object is returned containing a bearer token authorization header
Scenario
:
getAuthorizationHeader implicitly calls auth if required
Given
invalid config
When
the adapter instance is created
When
the getAuthorizationHeader method is called
Then
an error response is returned with status 403
\ No newline at end of file
This diff is collapsed.
Click to expand it.
features/adapter_token-valid.feature
0 → 100644
View file @
73605335
Feature
:
Is the token valid?
The adapter tokenValid method works as expected
Scenario
:
If adapter has not authed token is invalid
Given
valid config
When
the adapter instance is created
Then
tokenValid returns false
Scenario
:
If credentials.expiry is in the future token is valid
Given
valid config
When
the adapter instance is created
When
the auth method is called
When
the token expiry is in the future
Then
tokenValid returns true
Scenario
:
If credentials.expiry is in the past token is invalid
Given
valid config
When
the adapter instance is created
When
the auth method is called
When
the token expiry is in the past
Then
tokenValid returns false
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/broadcast.steps.js
View file @
73605335
const
assert
=
require
(
'
assert
'
);
const
{
When
,
Then
}
=
require
(
'
@cucumber/cucumber
'
);
const
{
When
}
=
require
(
'
@cucumber/cucumber
'
);
const
{
fixtures
}
=
require
(
'
../../fixtures/server
'
);
...
...
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/common.steps.js
0 → 100644
View file @
73605335
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/get-authorization-header.steps.js
0 → 100644
View file @
73605335
const
assert
=
require
(
'
assert
'
);
const
{
When
,
Then
}
=
require
(
'
@cucumber/cucumber
'
);
When
(
'
the getAuthorizationHeader method is called
'
,
function
()
{
this
.
call
=
this
.
adapter
.
getAuthorizationHeader
()
});
Then
(
'
a headers object is returned containing a bearer token authorization header
'
,
function
()
{
this
.
call
.
then
(
headers
=>
{
assert
.
ok
(
'
Authorization
'
in
headers
);
const
authHeaderWords
=
headers
.
Authorization
.
split
(
"
"
);
assert
.
ok
(
authHeaderWords
[
0
]
===
'
Bearer
'
);
assert
.
ok
(
authHeaderWords
[
1
]
===
this
.
adapter
.
credentials
.
token
);
});
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/token-valid.steps.js
0 → 100644
View file @
73605335
const
assert
=
require
(
'
assert
'
);
const
{
When
,
Then
}
=
require
(
'
@cucumber/cucumber
'
);
When
(
'
the token expiry is in the future
'
,
function
()
{
const
expiry
=
new
Date
();
expiry
.
setHours
(
expiry
.
getHours
()
+
1
);
this
.
adapter
.
credentials
.
expiry
=
expiry
.
toISOString
();
});
When
(
'
the token expiry is in the past
'
,
function
()
{
const
expiry
=
new
Date
();
expiry
.
setHours
(
expiry
.
getHours
()
-
1
);
this
.
adapter
.
credentials
.
expiry
=
expiry
.
toISOString
();
});
// Boolean parameters are not supported
// and returns "true" would be misleading
Then
(
'
tokenValid returns true
'
,
function
()
{
const
isValid
=
this
.
adapter
.
tokenValid
();
assert
.
ok
(
isValid
);
});
Then
(
'
tokenValid returns false
'
,
function
()
{
const
isValid
=
this
.
adapter
.
tokenValid
();
assert
.
ok
(
!
isValid
);
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment