Improve testing Keycloak
This commit is contained in:
parent
540f9bba96
commit
be534df9a2
@ -992,6 +992,49 @@ getAddUserR = do
|
||||
return $ Bool True
|
||||
Nothing -> return $ Bool False
|
||||
|
||||
addUserApi :: Swagger
|
||||
addUserApi = spec & definitions .~ defs
|
||||
where
|
||||
(defs, spec) = runDeclare declareAddUserApi mempty
|
||||
|
||||
declareAddUserApi :: Declare (Definitions Schema) Swagger
|
||||
declareAddUserApi = do
|
||||
-- param schemas
|
||||
response <- declareResponse (Proxy :: Proxy Bool)
|
||||
|
||||
return $ mempty
|
||||
& paths .~
|
||||
fromList [ ("/api/add-user",
|
||||
mempty & DS.get ?~ (mempty
|
||||
& parameters .~ [ ]
|
||||
& produces ?~ MimeList ["application/json"]
|
||||
& description ?~ "Creates a new user"
|
||||
& at 200 ?~ Inline response))
|
||||
]
|
||||
|
||||
|
||||
userInfoApi :: Swagger
|
||||
userInfoApi = spec & definitions .~ defs
|
||||
where
|
||||
(defs, spec) = runDeclare declareUserInfoApi mempty
|
||||
|
||||
declareUserInfoApi :: Declare (Definitions Schema) Swagger
|
||||
declareUserInfoApi = do
|
||||
-- param schemas
|
||||
response <- declareResponse (Proxy :: Proxy String)
|
||||
|
||||
return $ mempty
|
||||
& paths .~
|
||||
fromList [ ("/api/user-info",
|
||||
mempty & DS.get ?~ (mempty
|
||||
& parameters .~ [ ]
|
||||
& produces ?~ MimeList ["application/json"]
|
||||
& description ?~ "Returns the identifier of the user"
|
||||
& at 200 ?~ Inline response))
|
||||
]
|
||||
|
||||
|
||||
|
||||
declareAllSubmissionsApi :: String -> String -> Declare (Definitions Schema) Swagger
|
||||
declareAllSubmissionsApi q d = do
|
||||
-- param schemas
|
||||
|
@ -17,6 +17,8 @@ getSwaggerR = return $ toJSON apiDescription
|
||||
|
||||
apiDescription :: Swagger
|
||||
apiDescription = generalApi
|
||||
<> addUserApi
|
||||
<> userInfoApi
|
||||
<> listChallengesApi
|
||||
<> leaderboardApi
|
||||
<> allSubmissionsApi
|
||||
|
@ -108,6 +108,8 @@ If you create a new user, you need to run `/api/add-info` GET
|
||||
end-point. No parameters are needed it just read the user's data from
|
||||
the token and adds a record to the Gonito database.
|
||||
|
||||
You can simulate a front-end by going to `/static/test-gonito-as-backend.html`.
|
||||
|
||||
Gonito & git
|
||||
------------
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
keycloak = new Keycloak({
|
||||
url: 'http://127.0.0.1:8080/auth',
|
||||
realm: 'master',
|
||||
clientId: 'myapp',
|
||||
clientId: 'gonito',
|
||||
"enable-cors": true
|
||||
})
|
||||
keycloak.init({
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
var loadData = function (target) {
|
||||
|
||||
var url = 'http://127.0.0.1:3000/api/' + target;
|
||||
var url = '/api/' + target;
|
||||
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('GET', url, true);
|
||||
@ -60,12 +60,11 @@
|
||||
}
|
||||
xhr.setRequestHeader('Authorization', 'Bearer ' +
|
||||
keycloak.token);
|
||||
//xhr.setRequestHeader('Xyz', 'Blabla');
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
return xhr;
|
||||
};
|
||||
|
||||
var url = 'http://127.0.0.1:3000/api/list-challenges';
|
||||
var url = '/api/list-challenges';
|
||||
var method = 'GET';
|
||||
var xhr = createCORSRequest(method, url);
|
||||
|
||||
@ -86,9 +85,10 @@
|
||||
|
||||
<p><button onclick="loadData('add-user')">Add user</button></p>
|
||||
|
||||
<p><button onclick="loadData('user-info')">Check user</button></p>
|
||||
<p><button onclick="loadData('user-info')">Check user info</button></p>
|
||||
|
||||
<p><button onclick="loadData('challenge-my-submissions/retroc2')">Other test</button></p>
|
||||
<p><input type="text" id="challengeId" value="specify challenge ID here"/><button onclick="loadData('challenge-my-submissions/' + document.getElementById('challengeId').value)">Test
|
||||
showing user's submissions</button></p>
|
||||
|
||||
<p><button onclick="loadData('list-challenges')">Yet another
|
||||
test</button></p>
|
||||
|
Loading…
Reference in New Issue
Block a user