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
10d87d6d
Unverified
Commit
10d87d6d
authored
2 years ago
by
Dan Jones
Browse files
Options
Download
Email Patches
Plain Diff
test: initial tests of authentication
parent
43b2b99f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
40 deletions
+78
-40
features/adapter_works.feature
features/adapter_works.feature
+7
-3
features/is_it_friday_yet.feature
features/is_it_friday_yet.feature
+0
-7
features/step_definitions/stepdefs.js
features/step_definitions/stepdefs.js
+42
-30
test/fixtures/invalid-config.json
test/fixtures/invalid-config.json
+7
-0
test/fixtures/response-denied-token.json
test/fixtures/response-denied-token.json
+3
-0
test/fixtures/response-valid-token.json
test/fixtures/response-valid-token.json
+4
-0
test/fixtures/server.js
test/fixtures/server.js
+15
-0
test/fixtures/valid-config.json
test/fixtures/valid-config.json
+0
-0
No files found.
features/adapter_works.feature
View file @
10d87d6d
Feature
:
Does the adapter work?
The adapter behaves as expected
Scenario
:
Axios is mocked
Given
a mock adapter
Then
axios mock works
\ No newline at end of file
Scenario
:
A
token is granted with valid config
Given
valid config
Then
the adapter credentials are populated
Scenario
:
Auth fails with invalid config
Given
invalid config
Then
the adapter auth fails
\ No newline at end of file
This diff is collapsed.
Click to expand it.
features/is_it_friday_yet.feature
deleted
100644 → 0
View file @
43b2b99f
Feature
:
Is it Friday yet?
Everybody wants to know when it's Friday
Scenario
:
Sunday isn't Friday
Given
today is Sunday
When
I ask whether it's Friday yet
Then
I should be told
"Nope"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
features/step_definitions/stepdefs.js
View file @
10d87d6d
const
assert
=
require
(
'
assert
'
);
const
{
Given
,
When
,
Then
}
=
require
(
'
@cucumber/cucumber
'
);
const
{
Before
,
Given
,
When
,
Then
}
=
require
(
'
@cucumber/cucumber
'
);
var
axios
=
require
(
"
axios
"
);
var
MockAdapter
=
require
(
"
axios-mock-adapter
"
);
const
axios
=
require
(
"
axios
"
);
const
MockAdapter
=
require
(
"
axios-mock-adapter
"
);
// This sets the mock adapter on the default instance
var
mockAxios
=
new
MockAdapter
(
axios
);
const
mockAxios
=
new
MockAdapter
(
axios
);
const
{
fixtures
}
=
require
(
'
../../test/fixtures/server
'
);
const
mockValidConfig
=
fixtures
.
get
(
'
valid-config
'
);
const
mockInvalidConfig
=
fixtures
.
get
(
'
invalid-config
'
);
const
mockConfig
=
require
(
'
../../test/mock/config.json
'
);
const
mockSchema
=
require
(
'
../../test/mock/swagger.json
'
);
const
Adapter
=
require
(
'
../../
src
/adapter
'
);
const
GenericProtocol
=
require
(
'
../../
src
/protocol
'
);
const
{
Adapter
}
=
require
(
'
../../
dist
/adapter
'
);
const
{
GenericProtocol
}
=
require
(
'
../../
dist
/protocol
'
);
function
isItFriday
(
today
)
{
return
'
Nope
'
;
}
Before
(
function
()
{
Given
(
'
today is Sunday
'
,
function
()
{
this
.
today
=
'
Sunday
'
;
});
mockAxios
.
onGet
(
`
${
mockValidConfig
.
api
}
/token`
,
{
params
:
{
client_id
:
mockValidConfig
.
client_id
,
secret
:
mockValidConfig
.
secret
}
}
).
reply
(
200
,
fixtures
.
get
(
'
response-valid-token
'
));
mockAxios
.
onGet
(
`
${
mockInvalidConfig
.
api
}
/token`
,
{
params
:
{
client_id
:
mockInvalidConfig
.
client_id
,
secret
:
mockInvalidConfig
.
secret
}
}
).
reply
(
403
,
fixtures
.
get
(
'
response-denied-token
'
));
When
(
'
I ask whether it
\'
s Friday yet
'
,
function
()
{
this
.
actualAnswer
=
isItFriday
(
this
.
today
);
});
Then
(
'
I should be told {string}
'
,
function
(
expectedAnswer
)
{
assert
.
strictEqual
(
this
.
actualAnswer
,
expectedAnswer
);
Given
(
'
valid config
'
,
function
()
{
this
.
schema
=
mockSchema
;
this
.
config
=
mockValidConfig
});
Giv
en
(
'
a mock
adapter
'
,
function
()
{
let
mockProtocol
=
new
GenericProtocol
(
mockS
chema
);
let
mockAdapter
=
new
Adapter
(
mockProtocol
,
mockC
onfig
);
Th
en
(
'
the
adapter
credentials are populated
'
,
function
()
{
let
mockProtocol
=
new
GenericProtocol
(
this
.
s
chema
);
let
mockAdapter
=
new
Adapter
(
mockProtocol
,
this
.
c
onfig
);
this
.
adapter
=
mockAdapter
;
assert
.
equal
(
this
.
adapter
.
credentials
.
token
,
fixtures
.
get
(
'
response-valid-token
'
).
token
);
});
Then
(
'
axios mock works
'
,
function
()
{
// Mock any GET request to /users
// arguments for reply are (status, data, headers)
mock
.
onGet
(
"
/users
"
).
reply
(
200
,
{
users
:
[{
id
:
1
,
name
:
"
John Smith
"
}],
});
axios
.
get
(
"
/users
"
).
then
(
function
(
response
)
{
console
.
log
(
response
.
data
);
});
Given
(
'
invalid config
'
,
function
()
{
this
.
schema
=
mockSchema
;
this
.
config
=
mockInvalidConfig
;
});
Then
(
'
the adapter auth fails
'
,
function
()
{
assert
.
throws
(
function
()
{
let
mockProtocol
=
new
GenericProtocol
(
mockSchema
);
let
mockAdapter
=
new
Adapter
(
mockProtocol
,
mockInvalidConfig
);
this
.
adapter
=
mockAdapter
;
},
{
name
:
"
AxiosError
"
}
);
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/fixtures/invalid-config.json
0 → 100644
View file @
10d87d6d
{
"api"
:
"https://example.backbone.com/api"
,
"client_id"
:
"invalid-client-id"
,
"client_name"
:
"InvalidClientName"
,
"subscription"
:
"dot.delimited.topic.subscription.#"
,
"secret"
:
"TheCollaredDoveCoosInTheChimneyPot"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/fixtures/response-denied-token.json
0 → 100644
View file @
10d87d6d
{
"message"
:
"Invalid client credentials"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/fixtures/response-valid-token.json
0 → 100644
View file @
10d87d6d
{
"token"
:
"gAAAAABjwB-vxtER44M2en6xYyt7G1WXp8QwfsiHw-ijCqNBZpQPwxxrBHzUU1fQ9lfPPo4QHj50p-yh203dV6zLLoTzuiReqGzE2InqAxOwv4gddlQWNFJKyrmg4mVVMX2VZe2cCAljmHxEo66BHgt_T24AieedMnI4VR2kw4SFiooFv5nr2W8="
,
"expiry"
:
"2030-12-31T23:59:59.000000"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/fixtures/server.js
0 → 100644
View file @
10d87d6d
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
exports
.
fixtures
=
{
get
:
function
(
fixtureName
)
{
try
{
let
fixtureContent
=
fs
.
readFileSync
(
path
.
join
(
__dirname
,
`
${
fixtureName
}
.json`
));
let
fixture
=
JSON
.
parse
(
fixtureContent
);
return
fixture
;
}
catch
(
e
)
{
console
.
error
(
'
Fixture not found
'
,
fixrureName
);
return
null
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/
mock/
config.json
→
test/
fixtures/valid-
config.json
View file @
10d87d6d
File moved
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