Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-boot-admin
Commits
32cf0cba
Commit
32cf0cba
authored
Jun 30, 2018
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dont redirect to login when 401 is on `/instances/{id}/actuator/health`
closes #806
parent
06c80c46
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
6 deletions
+110
-6
package.json
spring-boot-admin-server-ui/package.json
+1
-0
axios.js
spring-boot-admin-server-ui/src/main/frontend/utils/axios.js
+10
-6
axios.spec.js
...oot-admin-server-ui/src/main/frontend/utils/axios.spec.js
+99
-0
No files found.
spring-boot-admin-server-ui/package.json
View file @
32cf0cba
...
@@ -86,6 +86,7 @@
...
@@ -86,6 +86,7 @@
"not ie < 11"
"not ie < 11"
],
],
"jest"
:
{
"jest"
:
{
"testURL"
:
"http://example.com"
,
"testRegex"
:
"spec.js$"
,
"testRegex"
:
"spec.js$"
,
"moduleFileExtensions"
:
[
"moduleFileExtensions"
:
[
"js"
,
"js"
,
...
...
spring-boot-admin-server-ui/src/main/frontend/utils/axios.js
View file @
32cf0cba
...
@@ -16,16 +16,20 @@
...
@@ -16,16 +16,20 @@
import
axios
from
'axios'
;
import
axios
from
'axios'
;
axios
.
interceptors
.
request
.
use
(
config
=>
{
export
const
addRequestedWithHeader
=
config
=>
{
config
.
headers
[
'X-Requested-With'
]
=
'XMLHttpRequest'
;
config
.
headers
[
'X-Requested-With'
]
=
'XMLHttpRequest'
;
return
config
;
return
config
;
}
)
;
};
axios
.
interceptors
.
response
.
use
(
response
=>
response
,
error
=>
{
const
isInstanceActuatorRequest
=
url
=>
url
.
match
(
/^instances
[/][^/]
+
[/]
actuator
([/]
.*
)?
$/
);
if
(
error
.
response
&&
error
.
response
.
status
===
401
)
{
window
.
location
=
`login?redirectTo=
${
encodeURIComponent
(
window
.
location
.
href
)}
`
;
export
const
redirectOn401
=
error
=>
{
if
(
error
.
response
&&
error
.
response
.
status
===
401
&&
!
isInstanceActuatorRequest
(
error
.
config
.
url
))
{
window
.
location
.
assign
(
`login?redirectTo=
${
encodeURIComponent
(
window
.
location
.
href
)}
`
);
}
}
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
}
)
;
};
axios
.
interceptors
.
request
.
use
(
addRequestedWithHeader
);
axios
.
interceptors
.
response
.
use
(
response
=>
response
,
redirectOn401
);
export
default
axios
;
export
default
axios
;
spring-boot-admin-server-ui/src/main/frontend/utils/axios.spec.js
0 → 100644
View file @
32cf0cba
/*
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
addRequestedWithHeader
,
redirectOn401
}
from
'./axios'
;
describe
(
'addRequestedWithHeader'
,
()
=>
{
it
(
'should add X-Requested-With header'
,
()
=>
{
const
config
=
{
headers
:
{
'Content-Type'
:
'application/json'
}
};
addRequestedWithHeader
(
config
);
expect
(
config
).
toEqual
({
headers
:
{
'Content-Type'
:
'application/json'
,
'X-Requested-With'
:
'XMLHttpRequest'
}
});
});
});
describe
(
'redirectOn401'
,
()
=>
{
it
(
'should not redirect on 500'
,
async
()
=>
{
window
.
location
.
assign
=
jest
.
fn
();
const
error
=
{
response
:
{
status
:
500
}
};
try
{
await
redirectOn401
(
error
);
}
catch
(
e
)
{
expect
(
e
).
toBe
(
error
);
}
expect
(
window
.
location
.
assign
).
not
.
toBeCalled
();
});
it
(
'should redirect on 401'
,
async
()
=>
{
window
.
location
.
assign
=
jest
.
fn
();
const
error
=
{
config
:
{
url
:
'instances/a973ff14be49'
},
response
:
{
status
:
401
}
};
try
{
await
redirectOn401
(
error
);
}
catch
(
e
)
{
expect
(
e
).
toBe
(
error
);
}
expect
(
window
.
location
.
assign
).
toBeCalledWith
(
'login?redirectTo=http%3A%2F%2Fexample.com%2F'
);
});
it
(
'should redirect on 401 for /instances/{id}/actuator/**'
,
async
()
=>
{
window
.
location
.
assign
=
jest
.
fn
();
const
error
=
{
config
:
{
url
:
'instances/a973ff14be49/actuator/health'
},
response
:
{
status
:
401
}
};
try
{
await
redirectOn401
(
error
);
}
catch
(
e
)
{
expect
(
e
).
toBe
(
error
);
}
expect
(
window
.
location
.
assign
).
not
.
toBeCalled
();
});
});
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