Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
924211b4
Commit
924211b4
authored
Aug 27, 2020
by
Piotr Gawron
Browse files
information about authentication token is put in the generated curl commands
parent
f6f99c65
Changes
3
Hide whitespace changes
Inline
Side-by-side
web/src/test/java/lcsb/mapviewer/web/ControllerIntegrationTest.java
View file @
924211b4
...
...
@@ -66,6 +66,7 @@ import lcsb.mapviewer.services.interfaces.IModelService;
import
lcsb.mapviewer.services.interfaces.IUserService
;
import
lcsb.mapviewer.web.config.SpringWebConfig
;
import
lcsb.mapviewer.web.utils.CommandFormatterWithReplacingPostFilenameHeader
;
import
lcsb.mapviewer.web.utils.CustomCurlRequestSnippet
;
@WebAppConfiguration
@ContextConfiguration
(
classes
=
SpringWebConfig
.
class
)
...
...
@@ -142,7 +143,7 @@ abstract public class ControllerIntegrationTest {
.
and
()
.
uris
().
withHost
(
"minerva-service.lcsb.uni.lu/minerva/api"
).
withPort
(
443
).
withScheme
(
"https"
)
.
and
().
snippets
().
withDefaults
(
CliDocumentation
.
curlRequest
(
new
CommandFormatterWithReplacingPostFilenameHeader
(
" \\%n "
)),
new
CustomCurlRequestSnippet
(
null
,
new
CommandFormatterWithReplacingPostFilenameHeader
(
" \\%n "
)),
CliDocumentation
.
httpieRequest
(),
HttpDocumentation
.
httpRequest
(),
HttpDocumentation
.
httpResponse
(),
...
...
web/src/test/java/lcsb/mapviewer/web/utils/CommandFormatterWithReplacingPostFilenameHeader.java
View file @
924211b4
...
...
@@ -7,6 +7,8 @@ import org.apache.logging.log4j.Logger;
import
org.springframework.restdocs.cli.CommandFormatter
;
import
org.springframework.util.CollectionUtils
;
import
lcsb.mapviewer.common.Configuration
;
/**
* This is a class for workaround the issue that when we put content of file
* inside the request we would like to provide human readable curl request.In
...
...
@@ -23,6 +25,12 @@ public class CommandFormatterWithReplacingPostFilenameHeader implements CommandF
private
String
separator
;
/**
* Information if in the formatted list of string there should also be
* information about session.
*/
private
boolean
session
=
false
;
public
CommandFormatterWithReplacingPostFilenameHeader
(
String
separator
)
{
this
.
separator
=
separator
;
}
...
...
@@ -45,6 +53,9 @@ public class CommandFormatterWithReplacingPostFilenameHeader implements CommandF
contentFileName
=
element
.
replace
(
"-H 'post-filename: "
,
""
).
replace
(
"'"
,
""
);
}
}
if
(
session
)
{
elements
.
add
(
"--cookie \""
+
Configuration
.
AUTH_TOKEN
+
"=xxxxxxxx\""
);
}
StringBuilder
result
=
new
StringBuilder
();
for
(
String
element
:
elements
)
{
...
...
@@ -59,4 +70,8 @@ public class CommandFormatterWithReplacingPostFilenameHeader implements CommandF
return
result
.
toString
();
}
public
void
setSessionAvailable
(
boolean
session
)
{
this
.
session
=
session
;
}
}
\ No newline at end of file
web/src/test/java/lcsb/mapviewer/web/utils/CustomCurlRequestSnippet.java
0 → 100644
View file @
924211b4
package
lcsb.mapviewer.web.utils
;
import
java.util.Map
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.restdocs.cli.CommandFormatter
;
import
org.springframework.restdocs.cli.CurlRequestSnippet
;
import
org.springframework.restdocs.operation.Operation
;
/**
* Custom modification of {@link CurlRequestSnippet} that documents the curl
* command for a request. The modification adds to the formatter information if
* session object was present in the query. This allows a formatter to add
* information about authentication token to the generated curl commands.
*
* @author Piotr Gawron
*
*/
public
class
CustomCurlRequestSnippet
extends
CurlRequestSnippet
{
Logger
logger
=
LogManager
.
getLogger
();
private
final
CommandFormatter
commandFormatter
;
public
CustomCurlRequestSnippet
(
CommandFormatter
commandFormatter
)
{
super
(
commandFormatter
);
this
.
commandFormatter
=
commandFormatter
;
}
public
CustomCurlRequestSnippet
(
Map
<
String
,
Object
>
attributes
,
CommandFormatter
commandFormatter
)
{
super
(
attributes
,
commandFormatter
);
this
.
commandFormatter
=
commandFormatter
;
}
@Override
protected
Map
<
String
,
Object
>
createModel
(
Operation
operation
)
{
Object
obj
=
operation
.
getAttributes
().
get
(
"org.springframework.mock.web.MockHttpServletRequest"
);
boolean
session
=
false
;
if
(
obj
instanceof
org
.
springframework
.
mock
.
web
.
MockHttpServletRequest
)
{
session
=
(((
org
.
springframework
.
mock
.
web
.
MockHttpServletRequest
)
obj
).
getSession
()
!=
null
);
}
if
(
commandFormatter
instanceof
CommandFormatterWithReplacingPostFilenameHeader
)
{
((
CommandFormatterWithReplacingPostFilenameHeader
)
commandFormatter
).
setSessionAvailable
(
session
);
}
return
super
.
createModel
(
operation
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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