opentrace-community / opentrace-cloud-functions

OpenTrace Cloud Functions. Reference implementation of the BlueTrace protocol.
https://bluetrace.io
GNU General Public License v3.0
273 stars 121 forks source link

Test functions fail: #encryption: should succeed in getting encryption key; #upload: should have valid buckets #18

Closed esQmo closed 4 years ago

esQmo commented 4 years ago

I'm trying to npm --prefix function test but only 2 tests succeed and 2 fails. Below are the errors:

1) config.ts
       #encryption
         should succeed in getting encryption key:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\DEVELOPMENT\Cloud\functions\test\opentrace\config.test.ts)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7)

  2) config.ts
       #upload
         should have valid buckets:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\DEVELOPMENT\Cloud\functions\test\opentrace\config.test.ts)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7)

I'm certain that the buckets are valid and the authorization are also given to the user. I'm on Windows.

Please assist.

Thanks

valduze commented 4 years ago

Hi @esQmo Please make sure that you created a secret and added a role you your firebase credentials to use it. The test function is trying to get the key but it's not finding it: Create a new secret in Secret Manager and add a new version with the key generated above. Note that this requires Billing enabled.

This is explained in cloud-functions under this section called: Encryption Key Thanks, Jongi

esQmo commented 4 years ago

Hello @valduze I did everything mentionned in the ReadMe file and even the more detailed one updated recently. Still failing at that step

qtangs commented 4 years ago

@esQmo, besides what @valduze mentioned, you need to ensure the steps specified at https://github.com/opentrace-community/opentrace-cloud-functions#test are done and you have the GOOGLE_APPLICATION_CREDENTIALS variable set.

You can run this command to test whether the variable is set correctly:

node -e 'const admin = require("firebase-admin"); admin.initializeApp(); admin.auth().listUsers(1).then(_ => console.log(_))'

It should output:

{ users: [ ... ], pageToken: '...' }

esQmo commented 4 years ago

@qtangs I have done all the steps, even started a new project.still stuck at the same step with the test! Can't past these 2 errors

val922 commented 4 years ago

@esQmo
cd https://github.com/opentrace-community/opentrace-cloud-functions/blob/master/functions/test/index.test.ts**

//import * as admin from "firebase-admin"; import config from "../src/config";

if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) { throw new Error("Environment variable GOOGLE_APPLICATION_CREDENTIALS is required to access Firebase. Refer to: https://cloud.google.com/docs/authentication/production "); } var admin = require("firebase-admin"); export const FunctionsTestWrapper = require("firebase-functions-test")({projectId: config.projectId});

if (admin.apps.length === 0) { var serAcc = require(process.env.GOOGLE_APPLICATION_CREDENTIALS); admin.initializeApp({credential: admin.credential.cert(serAcc), databaseURL: "https://{$PROJECT_ID}.firebaseio.com"}); }

alexissinglaire commented 4 years ago

@esQmo: hi, what steps.are you trying to do here? The firebase deploy or npm --prefix functions test?

Remember to run those 2 commands you need to run the export command for GOOGLE_APPLICATION_CREDENTIALS

export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/service-account.json"