Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage emulator custom metadata clear via setting null returns string 'null' for property #3385

Closed
mikehardy opened this issue May 19, 2021 · 4 comments · Fixed by #3403
Closed

Comments

@mikehardy
Copy link

[REQUIRED] Environment info

Hi there!

firebase-tools: 9.11.0

Platform: macOS 11.3.1

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

  1. start emulator
  2. configure client to use emulator, in this case I'm implementing storage.useEmulator support for react-native-firebase but we emulate firebase-js-sdk APIs so then run this code:
      const storageReference = firebase.storage().ref('testFile.txt');
      const metadata = await storageReference.updateMetadata({
        contentType: 'text/plain',
        customMetadata: {
          removeMe: 'please',
        },
      });

      metadata.customMetadata.removeMe.should.equal('please');

      const metadataAfterRemove = await storageReference.updateMetadata({
        contentType: 'text/plain',
        customMetadata: {
          removeMe: null,
        },
      });

      // FIXME this is failing
      console.error(JSON.stringify(metadataAfterRemove));
      should.equal(metadataAfterRemove.customMetadata.removeMe, undefined);

[REQUIRED] Expected behavior

customMetadata.removeMe should be undefined in javascript terms at that point?

[REQUIRED] Actual behavior

customMetadata.removeMe is the string null:

here's a paste of that console.error statement:

{"contentType":"text/plain","contentEncoding":"identity","contentDisposition":"inline","updated":"2021-05-18T21:58:16Z","timeCreated":"2021-05-18T21:55:47Z","contentLanguage":null,"generation":"1621392947873","name":"writeOnly.txt","size":10,"fullPath":"writeOnly.txt","customMetadata":{"removeMe":"null"},"metageneration":"1","cacheControl":null,"md5Hash":"o8152dbQWHKzkt84nfUEKg==","bucket":"react-native-firebase-testing.appspot.com"}

I'll try to put a commit hash in later once my storage emulator work is public

@samtstern
Copy link
Contributor

@mikehardy thanks for reporting! Sounds like a bug to me.

@mikehardy
Copy link
Author

I can chunk these out into different issues but I have a little batch of others as well. What's confusing about this little batch I mention just in this comment is that these are platform-specific, they fail when going through firebase-ios-sdk but not with going through firebase-android-sdk. I'm not sure how to track that down but you folks may have insight?

https://github.com/invertase/react-native-firebase/blob/fe3d22f54d0d706529eb5367795b568d9e783a4e/packages/storage/e2e/StorageReference.e2e.js#L373-L387

The FIXMEs here:

  describe('updateMetadata', function () {
    it('should return the updated metadata for a file', async function () {
      const storageReference = firebase.storage().ref(WRITE_ONLY_NAME);
      const metadata = await storageReference.updateMetadata({
        contentType: 'image/jpeg',
        cacheControl: 'true',
        contentDisposition: 'disposed',
        contentEncoding: 'encoded',
        contentLanguage: 'martian',
        customMetadata: {
          hello: 'world',
        },
      });

      metadata.customMetadata.hello.should.equal('world');
      metadata.generation.should.be.a.String();
      metadata.fullPath.should.equal(WRITE_ONLY_NAME);
      metadata.name.should.equal(WRITE_ONLY_NAME);
      metadata.size.should.be.a.Number();
      should.equal(metadata.size > 0, true);
      metadata.updated.should.be.a.String();
      metadata.timeCreated.should.be.a.String();
      metadata.contentEncoding.should.be.a.String();
      metadata.contentDisposition.should.be.a.String();
      if (device.getPlatform() === 'android') {
        // FIXME on iOS this is 'application/octet-stream'?
        metadata.contentType.should.equal('image/jpeg');
      }
      metadata.bucket.should.equal(`${firebase.app().options.projectId}.appspot.com`);
      metadata.metageneration.should.be.a.String();
      metadata.md5Hash.should.be.a.String();
      if (device.getPlatform() === 'android') {
        // FIXME on iOS this comes back null ?
        should.equal(metadata.cacheControl, 'true');
      }
      if (device.getPlatform() === 'android') {
        // FIXME on iOS this comes back null ?
        should.equal(metadata.contentLanguage, 'martian');
      }
      metadata.customMetadata.should.be.an.Object();
    });

Also this one

  describe('getMetadata', function () {
    it('should return a metadata for a file', async function () {
      const storageReference = firebase.storage().ref(`${PATH}/list/file1.txt`);
      const metadata = await storageReference.getMetadata();
      metadata.generation.should.be.a.String();
      metadata.fullPath.should.equal(`${PATH}/list/file1.txt`);
      if (device.getPlatform() === 'android') {
        // FIXME - iOS on emulator this is fullPath not name ?
        metadata.name.should.equal('file1.txt');
      }

If the emulator was at fault I would expect cross-platform behavior but these ones are platform-specific. Happy to help chase these down just not sure if they need to go here or in the SDK repos for ios / android

@samtstern
Copy link
Contributor

@abeisgoat has mentioned that there are many strange things about the iOS SDK ... so he will know what to do with these bugs.

@abeisgoat
Copy link
Contributor

Please file the iOS specific stuff as a new bug :)

Re the deleting metadata with null this is a known issue, fix coming this week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants