Skip to content

Commit

Permalink
fixed issue with activity upload when site upload fails
Browse files Browse the repository at this point in the history
unique file for precache
using new url
testing new app version with that shows only my projects
  • Loading branch information
temi committed Dec 7, 2024
1 parent 3f57e7f commit 9121b82
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 9 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ tasks.withType(Test) {
wiremock {
dir "${project.projectDir}/src/integration-test/resources/wiremock/"
params "--port=8018 --global-response-templating --local-response-templating"
// params "--port=8018 --global-response-templating --local-response-templating --verbose --print-all-network-traffic --record-mappings"
}

assets {
Expand Down
2 changes: 1 addition & 1 deletion grails-app/assets/javascripts/offline-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function ActivityViewModel (activity, parent) {
// if site update fails, reject the promise only if it is a new site.
// if existing site is update is reject, resolve the promise with the site id. This helps sync the activity.
// update can be rejected if user does not have permission on all the project the site is associated.
if (entities.utils.isDexieEntityId(site.siteId)) {
if (entities.utils.isDexieEntityId(id)) {
deferred.reject({error : error});
}
else {
Expand Down
1 change: 1 addition & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ environments {
temp.dir="/tmp/stylesheet"
google.maps.apiKey="testGoogleApi"
speciesCatalog.dir="./src/integration-test/resources/data"
userProfile.userIdAttribute="userid"
}

production {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class TemplateTagLib {
// We need the updated and original name to be cached by PWA.
originalFiles = originalFiles?.collect { "/assets/" + it }
List mixedFiles = resolvedFiles + originalFiles
mixedFiles = mixedFiles?.unique()

out << (mixedFiles as JSON).toString()
}
Expand Down
61 changes: 60 additions & 1 deletion src/integration-test/resources/dataset1/loadDataSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,64 @@ var activityProject = {
"termsOfUseAccepted" : true
};
db.project.insert(activityProject);
var project2 = {
"bushfireCategories" : [],
"origin" : "atlasoflivingaustralia",
"dateCreated" : ISODate("2022-04-07T07:12:58.072Z"),
"promoteOnHomepage" : "no",
"ecoScienceType" : [],
"countries" : [
"Australia"
],
"name" : "Test project 2",
"funding" : 0.0,
"isCitizenScience" : true,
"uNRegions" : [
"Oceania"
],
"industries" : [],
"tags" : [
"noCost"
],
"lastUpdated" : ISODate("2022-04-07T07:12:59.036Z"),
"isBushfire" : false,
"alaHarvest" : false,
"scienceType" : [
"Birds"
],
"isMERIT" : false,
"status" : "active",
"isSciStarter" : false,
"isExternal" : false,
"projectId" : "project_2",
"aim" : "Test Aim",
"associatedOrgs" : [],
"associatedProgram" : "Citizen Science Projects",
"baseLayer" : "",
"description" : "Test Description",
"facets" : [],
"fundings" : [],
"isEcoScience" : false,
"isWorks" : false,
"legalCustodianOrganisation" : "Atlas of Living Australia",
"legalCustodianOrganisationType" : "",
"projLifecycleStatus": "published",
"mapLayersConfig" : {
"baseLayers" : [],
"overlays" : []
},
"orgGrantee" : "",
"orgSponsor" : "",
"organisationId" : "3a04141a-2290-4c54-aee3-a433d60b4476",
"organisationName" : "Atlas of Living Australia",
"plannedStartDate" : ISODate("2022-04-06T14:00:00.000Z"),
"projectSiteId" : "ab9ec9af-241b-49f7-adcf-ca40e474d119",
"projectType" : "survey",
"regenerateProjectTimeline" : false,
"task" : "collect plants",
"termsOfUseAccepted" : true
};
db.project.insert(project2);
db.userPermission.insert({
entityType: 'au.org.ala.ecodata.Project',
entityId: activityProject.projectId,
Expand Down Expand Up @@ -159,7 +217,8 @@ db.projectActivity.insert(projectActivity);

var site = {
"projects" : [
"project_1"
"project_1",
"project_2"
],
"dateCreated" : ISODate("2022-04-07T07:12:56.343Z"),
"lastUpdated" : ISODate("2022-04-07T07:13:28.815Z"),
Expand Down
124 changes: 124 additions & 0 deletions src/integration-test/resources/wiremock/mappings/pwaDiscovery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"request": {
"urlPath": "/cas/oidc/.well-known/.well-known/openid-configuration",
"method": "GET"
},
"response": {
"status": 200,
"headers": {
"content-Type": "text/json"
},
"transformers": ["response-template"],
"jsonBody": {
"issuer": "http://{{request.host}}:{{request.port}}/cas/oidc",
"scopes_supported": [
"openid",
"profile",
"email",
"offline_access",
"ala",
"roles",
"users/read",
"users/write",
"ecodata/read_test",
"ecodata/write_test",
"biocache/read",
"biocache/write",
"ala/internal"
],
"response_types_supported": [
"code",
"token",
"id_token token"
],
"subject_types_supported": [
"public",
"pairwise"
],
"claim_types_supported": [
"normal"
],
"claims_supported": [
"sub",
"name",
"preferred_username",
"family_name",
"given_name",
"profile",
"locale",
"updated_at",
"email",
"email_verified",
"organisation",
"role",
"authority",
"city",
"state",
"country",
"userid"
],
"grant_types_supported": [
"authorization_code",
"password",
"client_credentials",
"refresh_token"
],
"id_token_signing_alg_values_supported": [
"RS256", "none"
],
"id_token_encryption_alg_values_supported": [
"none"
],
"id_token_encryption_enc_values_supported": [
"none"
],
"userinfo_signing_alg_values_supported": [
"RS256", "none"
],
"userinfo_encryption_alg_values_supported": [
"none"
],
"userinfo_encryption_enc_values_supported": [
"none"
],
"request_object_signing_alg_values_supported": [
"RS256", "none"
],
"request_object_encryption_alg_values_supported": [
"none"
],
"request_object_encryption_enc_values_supported": [
"none"
],
"introspection_endpoint_auth_methods_supported": [
"client_secret_basic"
],
"token_endpoint_auth_methods_supported": [
"client_secret_basic",
"client_secret_post",
"client_secret_jwt",
"private_key_jwt"
],
"code_challenge_methods_supported": [
"plain",
"S256"
],
"claims_parameter_supported": true,
"request_uri_parameter_supported": true,
"request_parameter_supported": true,
"backchannel_logout_supported": true,
"frontchannel_logout_supported": true,
"jwks_uri": "http://{{request.host}}:{{request.port}}/cas/oidc/jwks",
"authorization_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/oidcAuthorize",
"userinfo_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/oidcProfile",
"pushed_authorization_request_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/oidcPushAuthorize",
"registration_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/register",
"end_session_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/oidcLogout",
"introspection_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/introspect",
"revocation_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/revoke",
"backchannel_logout_session_supported": true,
"frontchannel_logout_session_supported": true,
"token_endpoint": "http://{{request.host}}:{{request.port}}/cas/oidc/oidcAccessToken"
}
}
}
46 changes: 40 additions & 6 deletions src/test/js/integration/pageobjects/StubbedCasSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class StubbedCasSpec {
n: "h5XN-_LL1yXb8oPWHOTNMby0Y6olpByVCNJGo1mjhk9PUoX8bfu6wNr4G7oR7O0NfIQVNLykqE7Q04RrP7JfexI97UuH5B0xBjHVo-S5SxeyUrVSQBpRu6EisQzxxF3a038a0GHYJpA5YUAZWD7Pux0yqJ5ly1y2Sn7uGb_JJ_bJ86EVWs3AxE1RZHmeY975A1kk470ylDAyfQuW_GU-gUzG5vdE1wAEIKe6GFtg5ulA_n_XVsrz9qio7ZtEyWZDAOCtk0jfg8iTJf5eLP2Q3D8ePy_6IvYvFDuQLmvKHn1jg5MnnDWZHV3GBRnfU8CtPu2ChFKhXedcrhQhhAWfKQ"
};
privateKey = '';
systemToken = '';
constructor () {
this.testConfig = browser.options.testConfig;
this.baseUrl = this.testConfig.baseUrl;
Expand All @@ -44,6 +45,7 @@ class StubbedCasSpec {

async loginAsPwaUser(expired = false) {
let userDetails = this.getUserDetails('1');
await this.setupUserProfileLookup(userDetails)
let {tokenSet, profile} = await this.setupOidcAuthForUser(userDetails, expired);
tokenSet.profile = profile;
let key = this.localStorageTokenKey;
Expand Down Expand Up @@ -84,6 +86,7 @@ class StubbedCasSpec {
getUserDetails(userId) {
return {
userId: userId,
username: userId,
email: `user${userId}@nowhere.com`,
firstName: "MERIT",
lastName: `User ${userId}`
Expand Down Expand Up @@ -159,7 +162,7 @@ class StubbedCasSpec {

// Stub the POST request for token exchange (using nock)
await this.setupAccessToken('/cas/oidc/oidcAccessToken', tokenSet, base64EncodedAuth);
let profile = await this.setupProfileEndpoint(userDetails, base64EncodedAuth);
let profile = await this.setupProfileEndpoint(userDetails, idToken);

// Return the ID token
return {tokenSet, profile};
Expand All @@ -185,6 +188,7 @@ class StubbedCasSpec {
let payload= {
at_hash: 'KX-L2Fj6Z9ow-gOpYfehRA',
sub: userDetails.userId,
username: userDetails.userId,
email_verified: true,
role: roles,
amr: 'DelegatedClientAuthenticationHandler',
Expand All @@ -209,6 +213,36 @@ class StubbedCasSpec {
return {payload, expiresIn, expiresAt};
}

async setupUserProfileLookup(userDetails) {
try {
await axios.post(`${this.testConfig.wireMockBaseUrl}/__admin/mappings`, {
request: {
method: 'POST',
url: this.testConfig.wireMockBaseUrl + '/userdetails/userDetails/getUserDetails',
queryParameters: {
userName: {
"equalTo": userDetails.userId
},
includeProps: {
"equalTo": "true"
}
}
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(userDetails),
transformers: ['response-template']
}
});
console.log('user lookup stub configured successfully.');
} catch (error) {
console.error('Error configuring stub:', error);
}
}

async setupAccessToken(url, body, base64EncodedAuth){
try {
// Set up POST request to "/cas/oidc/oidcAccessToken"
Expand Down Expand Up @@ -237,7 +271,7 @@ class StubbedCasSpec {
}
}

async setupProfileEndpoint(userDetails, base64EncodedAuth) {
async setupProfileEndpoint(userDetails, userToken){
// Create user profile
const profile = {
userid: userDetails.userId,
Expand All @@ -254,7 +288,7 @@ class StubbedCasSpec {
url: '/cas/oidc/oidcProfile',
headers: {
'Authorization': {
"equalTo": base64EncodedAuth
"equalTo": `Bearer ${userToken}`
}
}
},
Expand All @@ -278,12 +312,12 @@ class StubbedCasSpec {

let idTokenClaims = this.getTokenClaims(clientId)
// Simulate generating JWT (signing token) - Assuming you have RSA private key in 'privateKey'
let idToken = await this.signPayload(idTokenClaims);
let token = this.getToken(idToken);
this.systemToken = await this.signPayload(idTokenClaims);
let token = this.getToken(this.systemToken);

await this.setupAccessToken("/cas/oidc/oidcAccessToken", token, base64EncodedAuth);

return idToken
return this.systemToken;
}

getToken(idToken) {
Expand Down
2 changes: 1 addition & 1 deletion wdio.local.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const config = {
baseUrl: 'http://localhost:8087',
serverUrl: 'http://localhost:8087',
wireMockBaseUrl: 'http://localhost:8018',
pwaUrl: 'http://localhost:5173/pwa-mobile',
pwaUrl: 'http://localhost:5173/mobile-app',
proxyUrl: 'http://localhost:8081',
proxyPort: 8081,
dirName: __dirname,
Expand Down

0 comments on commit 9121b82

Please sign in to comment.