diff --git a/Jenkinsfile b/Jenkinsfile index 6415a6761..42c0991eb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,11 +27,11 @@ node { stage('Push image') { - docker.withRegistry('', 'dockerhub') { + docker.withRegistry('ghcr.io', 'sunbird-rc') { app.push("${env.BUILD_NUMBER}") app.push("latest") } - docker.withRegistry('', 'dockerhub') { + docker.withRegistry('ghrc.io', 'sunbird-rc') { claimApp.push("${env.BUILD_NUMBER}") claimApp.push("latest") } diff --git a/Makefile b/Makefile index a2181e557..fc4c3934f 100644 --- a/Makefile +++ b/Makefile @@ -52,18 +52,18 @@ test: build @docker-compose down @rm -rf db-data-2 || echo "no permission to delete" # test with fusionauth - @RELEASE_VERSION=latest DB_DIR=db-data-7 SEARCH_PROVIDER_NAME=dev.sunbirdrc.registry.service.NativeSearchService FUSION_WRAPPER_BUILD=services/sample-fusionauth-service/ FUSIONAUTH_ISSUER_URL=http://fusionauth:9011/ oauth2_resource_uri=http://fusionauth:9011/ oauth2_resource_roles_path=roles identity_provider=dev.sunbirdrc.auth.genericiam.AuthProviderImpl sunbird_sso_url=http://fusionauthwrapper:3990/fusionauth/api/v1/user IMPORTS_DIR=services/sample-fusionauth-service/imports docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml up -d db es fusionauth fusionauthwrapper + @docker-compose --env-file test_environments/test_with_fusionauth.env -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml up -d db es fusionauth fusionauthwrapper sleep 20 @echo "Starting the test" && sh build/wait_for_port.sh 9011 @echo "Starting the test" && sh build/wait_for_port.sh 3990 sleep 20 - @RELEASE_VERSION=latest DB_DIR=db-data-7 SEARCH_PROVIDER_NAME=dev.sunbirdrc.registry.service.NativeSearchService FUSION_WRAPPER_BUILD=services/sample-fusionauth-service/ FUSIONAUTH_ISSUER_URL=http://fusionauth:9011/ oauth2_resource_uri=http://fusionauth:9011/ oauth2_resource_roles_path=roles identity_provider=dev.sunbirdrc.auth.genericiam.AuthProviderImpl sunbird_sso_url=http://fusionauthwrapper:3990/fusionauth/api/v1/user IMPORTS_DIR=services/sample-fusionauth-service/imports docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml up -d --no-deps registry + @docker-compose --env-file test_environments/test_with_fusionauth.env -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml up -d --no-deps registry @echo "Starting the test" && sh build/wait_for_port.sh 8081 @docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml ps @curl -v http://localhost:8081/health @cd java/apitest && MODE=fusionauth ../mvnw -Pe2e test || echo 'Tests failed' @docker-compose -f docker-compose.yml -f services/sample-fusionauth-service/docker-compose.yml down - @rm -rf db-data-7 || echo "no permission to delete" + @rm -rf db-data-3 || echo "no permission to delete" make -C services/certificate-signer test make -C services/public-key-service test make -C services/context-proxy-service test diff --git a/java/apitest/src/test/java/e2e/registry/certificate.feature b/java/apitest/src/test/java/e2e/registry/certificate.feature index f1c86b755..4795fe69f 100644 --- a/java/apitest/src/test/java/e2e/registry/certificate.feature +++ b/java/apitest/src/test/java/e2e/registry/certificate.feature @@ -2,6 +2,8 @@ Feature: Get certificate pdf Background: * def certUrl = "http://localhost:8078" * def templateBody = {"certificate": "{\"name\":\"Test Name\", \"dob\":\"2002-12-22\"}","templateUrl": "http://registry:8081/api/v1/templates/Student.html"} + + @envnot=fusionauth Scenario: And header Accept = 'application/pdf' Given url certUrl @@ -11,6 +13,7 @@ Feature: Get certificate pdf Then status 200 #* print response + @envnot=fusionauth Scenario: And header Accept = 'application/pdf' Given url certUrl diff --git a/java/apitest/src/test/java/e2e/registry/registry.feature b/java/apitest/src/test/java/e2e/registry/registry.feature index 8031a5721..90f96af73 100644 --- a/java/apitest/src/test/java/e2e/registry/registry.feature +++ b/java/apitest/src/test/java/e2e/registry/registry.feature @@ -9,12 +9,12 @@ Feature: Registry api tests * def admin_token = "" * def client_secret = 'a52c5f4a-89fd-40b9-aea2-3f711f14c889' * def sleep = function(millis){ java.lang.Thread.sleep(millis) } - + @envnot=fusionauth Scenario: health check Given path 'health' When method get Then status 200 - + @envnot=fusionauth Scenario: Create birth certificate schema and issue credentials # get admin token * url authUrl @@ -102,7 +102,7 @@ Feature: Registry api tests And response.params.status == "UNSUCCESSFUL" And response.params.errmsg == "entity status is inactive" - + @envnot=fusionauth Scenario: Create student schema and verify crud apis # get admin token * url authUrl @@ -234,6 +234,7 @@ Feature: Registry api tests And response.length == 1 And response[0].contact == '#notpresent' + @envnot=fusionauth Scenario: Create Board and invite institutes # get admin token * url authUrl @@ -347,6 +348,7 @@ Feature: Registry api tests And assert response[0].address[0].phoneNo.length == 1 And assert response[0].address[0].phoneNo[0] == "444" + @envnot=fusionauth Scenario: write a api test, to test the schema not found error # get admin token * url authUrl @@ -486,6 +488,7 @@ Feature: Registry api tests And response.params.status =="UNSUCCESSFUL" And response.params.errmsg == "Schema 'Teacher1' not found" + @envnot=fusionauth Scenario: Create student with password schema and verify if password is set # get admin token * url authUrl @@ -544,6 +547,8 @@ Feature: Registry api tests When method get Then status 200 * match response.contactDetails == { mobile: '#notpresent', email: '#present', osid: '#present' } + + @envnot=fusionauth Scenario: Create birth certificate schema, issue credentials then revoke the credential and check for CRUD APIS # get admin token * url authUrl @@ -678,6 +683,7 @@ Feature: Registry api tests And print response[notificationStudent] And assert response[notificationStudent] != null + @envnot=fusionauth Scenario: Test unique constraints with nested and composite fields # create entity Given url registryUrl diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/config/GenericConfiguration.java b/java/registry/src/main/java/dev/sunbirdrc/registry/config/GenericConfiguration.java index b16b16b47..fb48adcc5 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/config/GenericConfiguration.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/config/GenericConfiguration.java @@ -64,11 +64,7 @@ import dev.sunbirdrc.registry.identity_providers.providers.IdentityProvider; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.HashSet; +import java.util.*; import static dev.sunbirdrc.registry.Constants.ATTESTATION_POLICY; diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java index 73d719d8c..c0bebdf18 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/controller/RegistryEntityController.java @@ -663,11 +663,11 @@ public ResponseEntity getEntityByToken(@PathVariable String entityName, Response response = new Response(Response.API_ID.GET, "OK", responseParams); try { checkEntityNameInDefinitionManager(entityName); - String userId = registryHelper.getUserId(request, entityName); + String userId = registryHelper.getUserId(entityName); if (!Strings.isEmpty(userId)) { JsonNode responseFromDb = registryHelper.searchEntitiesByUserId(entityName, userId, viewTemplateId); JsonNode entities = responseFromDb.get(entityName); - if (entities.size() > 0) { + if (!entities.isEmpty()) { return new ResponseEntity<>(entities, HttpStatus.OK); } else { responseParams.setErrmsg("No record found"); diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java b/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java index cddd0b35f..88fccab75 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/helper/RegistryHelper.java @@ -434,8 +434,14 @@ public String triggerAttestation(AttestationRequest attestationRequest, Attestat updateGetFileUrl(attestationRequest.getAdditionalInput()); + String propertyData = null; + if (attestationRequest.getPropertyData() != null) { + propertyData = attestationRequest.getPropertyData().toString(); + } + + PluginRequestMessage message = PluginRequestMessageCreator.create( - attestationRequest.getPropertyData().toString(), condition, attestationOSID, attestationRequest.getEntityName(), + propertyData, condition, attestationOSID, attestationRequest.getEntityName(), attestationRequest.getEmailId(), attestationRequest.getEntityId(), attestationRequest.getAdditionalInput(), Action.RAISE_CLAIM.name(), attestationPolicy.getName(), attestationPolicy.getAttestorPlugin(), attestationPolicy.getAttestorEntity(), attestationPolicy.getAttestorSignin(), @@ -484,7 +490,9 @@ private void addAttestationProperty(AttestationRequest attestationRequest) throw JsonNode parentNode = nodeToUpdate.get(attestationRequest.getEntityName()); JsonNode propertyNode = parentNode.get(attestationRequest.getName()); ObjectNode attestationJsonNode = (ObjectNode) JSONUtil.convertObjectJsonNode(attestationRequest); - attestationJsonNode.set("propertyData", JsonNodeFactory.instance.textNode(attestationRequest.getPropertyData().toString())); + if (attestationRequest.getPropertyData() != null) { + attestationJsonNode.set("propertyData", JsonNodeFactory.instance.textNode(attestationRequest.getPropertyData().toString())); + } createOrUpdateProperty(attestationRequest.getEntityName(), attestationJsonNode, nodeToUpdate, attestationRequest.getName(), (ObjectNode) parentNode, propertyNode); updateEntityAndState(existingEntityNode, nodeToUpdate, attestationRequest.getUserId()); } diff --git a/services/certificate-api/main.js b/services/certificate-api/main.js index 051bcba46..86a4927f6 100644 --- a/services/certificate-api/main.js +++ b/services/certificate-api/main.js @@ -1,56 +1,33 @@ -const axios = require('axios'); -let token = ''; -let osids = [""]; -osids.forEach(osid => { - - - let config = { - method: 'get', - maxBodyLength: Infinity, - url: 'http://localhost:8081/api/v1/ProofOfAchievement/'+osid, - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + token, +const certificateController = require("./src/routes/certificate_controller"); +const http = require('http'); +const port = process.env.PORT || 4321; + +const server = http.createServer(async (req, res) => { + const label = `${req.url}-${new Date().getTime()}`; + console.time(label) + console.log(`API ${req.method} ${req.url} called`); + try { + if (req.method === 'GET' && req.url.startsWith("/health")) { + res.end("OK") + } else if (req.method === 'POST' && req.url.startsWith("/api/v1/certificate") && ["application/pdf"].includes(req.headers.accept)) { + const data = await certificateController.getCertificatePDF(req, res); + res.end(data) + } else if (req.method === 'POST' && req.url.startsWith("/api/v1/certificate") && ["text/html", "image/svg+xml"].includes(req.headers.accept)) { + const data = await certificateController.getCertificate(req, res); + res.end(data) + } else { + res.statusCode = 404; + res.end("Not found"); } - }; - - axios.request(config) - .then((response) => { - const getResp = response.data; - delete getResp["osUpdatedAt"] - delete getResp["osUpdatedBy"] - delete getResp["_osSignedData"] - delete getResp["osOwner"] - delete getResp["osCreatedAt"] - delete getResp["osCreatedBy"] - getResp["achievementTitle"] = "Participation" - console.log(getResp) - let config = { - method: 'put', - maxBodyLength: Infinity, - url: 'http://localhost:8081/api/v1/ProofOfAchievement/' + getResp["osid"], - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + token, - }, - data : getResp - }; - - axios.request(config) - .then((response) => { - console.log(JSON.stringify(response.data)); - }) - .catch((error) => { - console.log(error); - }); - - - }) - .catch((error) => { - console.log(error); - }); -}) - - - + } finally { + if (!res.writableEnded) { + res.statusCode = 500; + res.end("Error occurred"); + } + } + console.timeEnd(label) +}); +server.listen(port, async () => { + console.log(`Server listening on port ${port}`); +}); diff --git a/test_environments/test_with_fusionauth.env b/test_environments/test_with_fusionauth.env new file mode 100644 index 000000000..36f2c099d --- /dev/null +++ b/test_environments/test_with_fusionauth.env @@ -0,0 +1,10 @@ +RELEASE_VERSION=latest +DB_DIR=db-data-3 +SEARCH_PROVIDER_NAME=dev.sunbirdrc.registry.service.NativeSearchService +FUSION_WRAPPER_BUILD=services/sample-fusionauth-service/ +FUSIONAUTH_ISSUER_URL=http://fusionauth:9011/ +oauth2_resource_uri=http://fusionauth:9011/ +oauth2_resource_roles_path=roles +identity_provider=dev.sunbirdrc.auth.genericiam.AuthProviderImpl +sunbird_sso_url=http://fusionauthwrapper:3990/fusionauth/api/v1/user +IMPORTS_DIR=services/sample-fusionauth-service/imports