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

Fix export users #1690

Merged
merged 3 commits into from
Oct 8, 2019
Merged

Fix export users #1690

merged 3 commits into from
Oct 8, 2019

Conversation

kossnocorp
Copy link
Contributor

Description

This PR fixes a bug in auth.export command. When serialExportUsers function (used by the command) is called more than once, it adds a redundant comma, which breaks the JSON format.

The first call:

{"users": [
{
  "localId": "DxADx87BFyPe8HhD4dOAyuwXECu1",
  ...

The second call (and all consecutive):

{"users": [
,
{
  "localId": "DxADx87BFyPe8HhD4dOAyuwXECu1",
  ...

The bug is caused by a global variable jsonSep in an internal _writeUsersToFile function. I assume that it was first introduced to make JSON streamable.

I changed the code to make it generate writeUsersToFile shared among recursive calls.

Scenarios Tested

When the package is used via Node.js API:

import * as tools from 'firebase-tools'
tools.auth.export(path)

Always produce valid JSON. Before the changes, the second tools.auth.export call produces malformed JSON (see the , as the first array element):

{"users": [
,
{
  "localId": "DxADx87BFyPe8HhD4dOAyuwXECu1"
},
{
  "localId": "hoW2ffPbIpW3ToLpxmk86lymT5w2"
},
{
  "localId": "z2ppbzpxMwbwpQhqTqKhrerM2rZ2"
}]}

@googlebot googlebot added the cla: yes Manual indication that this has passed CLA. label Oct 5, 2019
@coveralls
Copy link

coveralls commented Oct 5, 2019

Coverage Status

Coverage increased (+0.05%) to 65.104% when pulling 475567d on kossnocorp:fix-export-users into 790209c on firebase:master.

@samtstern samtstern requested a review from bkendall October 7, 2019 15:49
@samtstern
Copy link
Contributor

@kossnocorp thanks for your contribution! Assigning this one to @bkendall who reviewed code on this path recently.

Copy link
Contributor

@bkendall bkendall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a reasonable fix to me. Thanks for the PR. A couple things to clean up in the test, but should be easy enough.

Please also

  1. Sync with master
  2. Add an entry to CHANGELOG.md, maybe:
* Fixes invalid JSON output in `auth.export` within a scripting environment.

src/test/accountExporter.spec.js Outdated Show resolved Hide resolved
@kossnocorp
Copy link
Contributor Author

@bkendall thank you for the review, I'll address that.

When `serialExportUsers` function is called more than once,
it adds a redundant comma, which breaks the JSON format.

The first call:

```
{"users": [
{
  "localId": "DxADx87BFyPe8HhD4dOAyuwXECu1",
  ...
```

The second call (and all consecutive):

```
{"users": [
,
{
  "localId": "DxADx87BFyPe8HhD4dOAyuwXECu1",
  ...
```
When `serialExportUsers` function is called more than once,
it adds a redundant comma, which breaks the JSON format.

The bug is caused by a global variable `jsonSep` in an internal
`_writeUsersToFile` function. I assume that it was first introduced
to make JSON streamable.

I changed the code to make it generate `writeUsersToFile`
shared among recursive calls.
@kossnocorp kossnocorp requested a review from bkendall October 8, 2019 08:22
@bkendall
Copy link
Contributor

bkendall commented Oct 8, 2019

Thanks for the PR!

@bkendall bkendall merged commit 33da3e4 into firebase:master Oct 8, 2019
Elgarni added a commit to Elgarni/firebase-tools that referenced this pull request Oct 9, 2019
* master:
  change out tslint for eslint, new publish config (firebase#486)
  Remove scripts/package.json and update firebase version. (firebase#1704)
  Fix functions deploy integration test script (firebase#1703)
  Loop the modules properties without prototype methods. Fixes firebase#1687 (firebase#1694)
  Allow customers to configure the db setting 'strictTriggerValidation' (firebase#1702)
  [firebase-release] Removed change log and reset repo after 7.5.0 release
  7.5.0
  Fix export users (firebase#1690)
  Fix port issues in WSL (firebase#1699)
  Unremove but deprecate separate port for WebChannel. (firebase#1698)
  Release Firestore Emulator 1.9.0 and remove WebChannel workaround. (firebase#1689)
  update handlebars dependency (firebase#1686)
  [firebase-release] Removed change log and reset repo after 7.4.0 release
  7.4.0
  remove items from previews list (firebase#488)
@kossnocorp kossnocorp deleted the fix-export-users branch October 16, 2019 11:22
@kossnocorp
Copy link
Contributor Author

You're very welcome, thank you for a great platform!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants