firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.63k stars 371 forks source link

firebase - Error: The creation time must be a valid UTC date string #297

Closed kincjf closed 6 years ago

kincjf commented 6 years ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

Error: The creation time must be a valid UTC date string.[0m[90m
  at FirebaseAuthError.FirebaseError [as constructor] (node_modules\firebase-admin\lib\utils\error.js:39:28)
  at FirebaseAuthError.PrefixedFirebaseError [as constructor] (node_modules\firebase-admin\lib\utils\error.js:85:28)
  at new FirebaseAuthError (node_modules\firebase-admin\lib\utils\error.js:143:16)
  at validateCreateEditRequest (node_modules\firebase-admin\lib\auth\auth-api-request.js:194:15)
  at D:\webstorm_workspace\pixelcity-new-local-server\functions\node_modules\firebase-admin\lib\auth\auth-api-request.js:346:5
  at D:\webstorm_workspace\pixelcity-new-local-server\functions\node_modules\firebase-admin\lib\auth\auth-api-request.js:700:13
  at <anonymous>
From previous event:
From previous event:
  at listAllUsers.then.then (test\test.online.js:118:20)
  at <anonymous>

We are unit testing firebase auth, database, cloudfunction using mocha framework

I tried to create test.database.makeDataSnapshot, but it was not created due to a firebase core error (JSON.parse - unable to parse "u" ...).

So I updated the whole npm package today and I get the above of error

It is the code that was originally passed, but the error occurred because the update package was done, and the related issue/docs is not retrieved.

How can I solve this?

Relevant Code:


....
describe('Test Cloud Functions', () => {
let initData;
let uid = "antiqueUid";

before((done) => {
    // Require index.js and save the exports inside a namespace called myFunctions.
    // This includes our cloud functions, which can now be accessed at myFunctions.makeUppercase
    // and myFunctions.addMessage
    initData = require("../../build/pixelcity-demo-48860.export");
    myFunction = require('../index');

    // 강제 debug break point 진입
    if (typeof(v8debug) !== undefined) {
        debugger;
    }

    // Do cleanup tasks.
    test.cleanup();

    // Resolution method is overspecified. Specify a only callback *or* only return a Promise; not both!!
    // 내부적으로는 promise chain으로 연결되어야하고, 외부 최초 return은 callback처럼 작성하기
    // callback type과 promise 타입을 섞어서 쓰면 작동을 안한다
    admin.database().ref('/').remove().then(() => {
        users = [];

        return listAllUsers(users).then(users => {
            return Promise.each(users, (item) => {
                return admin.auth().deleteUser(item.uid);
            }).then(() => {
                let userCountRef = admin.database().ref("saving-data/count");
                return userCountRef.update({
                    "user": 0
                });
            });
            // end clear data
        }).then(() => {
            return Promise.each(objectToArray(initData.user), (item, index, length) => {
                item.value.password = "11112222";
                return admin.auth().createUser(item.value);
            });
        }).then(() => {
            return admin.database().ref('/').set(initData);
        }).then((ref) => {
            let userArr = [];

            return listAllUsers(userArr).then((users) => {
                let userCountRef = admin.database().ref("saving-data/count/user");

                return userCountRef.transaction(function (current_value) {
                    let userCount = users.length;
                    return userCount;
                });
            });
            // end dump test data
        });
    }).then(() => done()).catch((err) => done(err));
});
....
    describe('signupTrigger', () => {
    before((done) => {
        users = [];
        done(); // done()을 안하면 멈춰서 다음 case로 넘어가지지 않는다
    });

    it('should occur signupTrigger when user created(cloud database onCreate)', (done) => {
        // [START assertOnline]
        // Create a DataSnapshot with the value 'input' and the reference path 'messages/11111/original'.
        let mockVal = {
            uid: uid,
            email: "testandtest.net"
        };
        let mockRefPath = 'user/' + uid;
        const snap = test.database.makeDataSnapshot(mockVal, mockRefPath, admin.app());

        // Wrap the makeUppercase function
        const wrappedSignupTrigger = test.wrap(myFunctions.signupTrigger);
        // Call the wrapped function with the snapshot you constructed.
        return wrappedSignupTrigger(snap).then(() => {
            // Read the value of the data at messages/11111/uppercase. Because `admin.initializeApp()` is
            // called in functions/index.js, there's already a Firebase app initialized. Otherwise, add
            // `admin.initializeApp()` before this line.
            return admin.database().ref('userProperty/' + uid).once('value').then((createdSnap) => {
                let val = createdSnap.val();
                // Assert that the value is the uppercased version of our input.
                assert.equal(val.level, 1, `userProperty/${uid}/level: ${val.level}`);

                return admin.database().ref("saving-data/count/user").once('value').then((currentSnap) => {
                    let currentUserLength = currentSnap.val();
                    let prevUserLength = objectToArray(initData.user).length;

                    assert.equal(currentUserLength, prevUserLength + 1, `saving-data/count/user: ${currentUserLength}`);
                    return Promise.resolve();
                });
            }).then(() => done()).catch((err) => done(err));
        });
        // [END assertOnline]
    });
});
....```
google-oss-bot commented 6 years ago

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

google-oss-bot commented 6 years ago

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

hiranya911 commented 6 years ago

Can you provide a minimal, complete and reproducible test case please? Your code is partial but does a lot of things. It's not clear where the problem is occurring.

kincjf commented 6 years ago
        return Promise.each(objectToArray(initData.user), (item, index, length) => {
            item.value.password = "11112222";
            return admin.auth().createUser(item.value); <= This is the section where the actual error occurs when debugging
        });

When I check the internal library of firebase-admin through debug, I seem to output the above error because the firebase-admin library try to JSON.parse with undefined in process.env.FIREBASE_CONFIG Using the firebase-admin library works fine, but I did not know why that part was error

kincjf commented 6 years ago

I solved the problem! There was a variable "item.value.createdAt" An error occurred when I entered the value of utc string for that variable. So once I removed createdAt, it was fixed