Improve testing Keycloak

This commit is contained in:
Filip Gralinski 2021-04-27 11:49:22 +02:00
parent 540f9bba96
commit be534df9a2
4 changed files with 53 additions and 6 deletions

View File

@ -992,6 +992,49 @@ getAddUserR = do
return $ Bool True return $ Bool True
Nothing -> return $ Bool False 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 :: String -> String -> Declare (Definitions Schema) Swagger
declareAllSubmissionsApi q d = do declareAllSubmissionsApi q d = do
-- param schemas -- param schemas

View File

@ -17,6 +17,8 @@ getSwaggerR = return $ toJSON apiDescription
apiDescription :: Swagger apiDescription :: Swagger
apiDescription = generalApi apiDescription = generalApi
<> addUserApi
<> userInfoApi
<> listChallengesApi <> listChallengesApi
<> leaderboardApi <> leaderboardApi
<> allSubmissionsApi <> allSubmissionsApi

View File

@ -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 end-point. No parameters are needed it just read the user's data from
the token and adds a record to the Gonito database. 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 Gonito & git
------------ ------------

View File

@ -8,7 +8,7 @@
keycloak = new Keycloak({ keycloak = new Keycloak({
url: 'http://127.0.0.1:8080/auth', url: 'http://127.0.0.1:8080/auth',
realm: 'master', realm: 'master',
clientId: 'myapp', clientId: 'gonito',
"enable-cors": true "enable-cors": true
}) })
keycloak.init({ keycloak.init({
@ -23,7 +23,7 @@
var loadData = function (target) { var loadData = function (target) {
var url = 'http://127.0.0.1:3000/api/' + target; var url = '/api/' + target;
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open('GET', url, true); req.open('GET', url, true);
@ -60,12 +60,11 @@
} }
xhr.setRequestHeader('Authorization', 'Bearer ' + xhr.setRequestHeader('Authorization', 'Bearer ' +
keycloak.token); keycloak.token);
//xhr.setRequestHeader('Xyz', 'Blabla');
xhr.setRequestHeader('Accept', 'application/json'); xhr.setRequestHeader('Accept', 'application/json');
return xhr; return xhr;
}; };
var url = 'http://127.0.0.1:3000/api/list-challenges'; var url = '/api/list-challenges';
var method = 'GET'; var method = 'GET';
var xhr = createCORSRequest(method, url); var xhr = createCORSRequest(method, url);
@ -86,9 +85,10 @@
<p><button onclick="loadData('add-user')">Add user</button></p> <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 <p><button onclick="loadData('list-challenges')">Yet another
test</button></p> test</button></p>