Skip to content

Commit

Permalink
Merge pull request #734 from kuzzleio/7-dev
Browse files Browse the repository at this point in the history
fix: (ProfilePolicy.ts) restrictedTo was mistyped (#733)
  • Loading branch information
rolljee authored Dec 5, 2023
2 parents e4bdf50 + 0938207 commit 16903e4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/actions/es-lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ runs:
using: "composite"
steps:
- name: Install deps
run: npm i -g npm && npm install
run: npm ci
shell: bash
- name: Run lint
run: npm run test:lint
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/functional-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
shell: bash
- name: Build Kuzzle
run: |
npm install
npm ci
npm run build
shell: bash
- name: Run functional tests
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/snippet-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ runs:
steps:
- name: Build the Stack
run: |
npm install
npm ci
npm run build
shell: bash
- run: npm run doc-testing
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/unit-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
steps:
- name: Run build
run: |
npm install
npm ci
npm run build
shell: bash
- name: Run tests
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/push_branches.workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- uses: convictional/[email protected]
- name: Deploy the documentation
uses: convictional/[email protected]
with:
owner: kuzzleio
repo: documentation
github_token: ${{ secrets.ACCESS_TOKEN_CI }}
workflow_file_name: child_repo.workflow.yml
ref: ${{ github.ref_name == 'master' && 'master' || 'develop' }}
client_payload: '{"repo_name":"sdk-javascript","branch":"${{ github.ref_name }}","version":"1"}'
client_payload: '{"repo_name":"sdk-javascript","branch":"${{ github.ref_name }}","version":"7"}'
14 changes: 12 additions & 2 deletions src/protocols/Http.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

import staticHttpRoutes from "./routes.json";
import { KuzzleAbstractProtocol } from "./abstract/Base";
import { HttpRoutes, JSONObject } from "../types";
import { RequestPayload } from "../types/RequestPayload";
import { KuzzleAbstractProtocol } from "./abstract/Base";
import staticHttpRoutes from "./routes.json";

/**
* Http protocol used to connect to a Kuzzle server.
Expand Down Expand Up @@ -405,6 +405,11 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {
);
}

const contentType = response.headers["content-type"];
if (!contentType || !contentType.includes("application/json")) {
return response.body;
}

return JSON.parse(response.body);
});
}
Expand Down Expand Up @@ -435,6 +440,11 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {

xhr.onload = () => {
try {
const contentType = xhr.getResponseHeader("Content-Type");
if (!contentType || !contentType.includes("application/json")) {
resolve(xhr.responseText);
return;
}
const json = JSON.parse(xhr.responseText);
resolve(json);
} catch (err) {
Expand Down
26 changes: 14 additions & 12 deletions src/types/ProfilePolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ export type ProfilePolicy = {
/**
* Optional array of restrictions on which the rights are gonne be applied
*/
restrictedTo?: {
/**
* Index name.
* Rights will only be applied on this index.
*/
index: string;
restrictedTo?: [
{
/**
* Index name.
* Rights will only be applied on this index.
*/
index: string;

/**
* Collection names.
* Rights will only be applied on those collections.
*/
collections?: Array<string>;
};
/**
* Collection names.
* Rights will only be applied on those collections.
*/
collections?: Array<string>;
}
];
};
10 changes: 7 additions & 3 deletions test/protocol/Http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,12 @@ describe("HTTP networking module", () => {
let httpRequestStub;

beforeEach(() => {
httpRequestStub = sinon
.stub()
.resolves({ body: JSON.stringify(mockResponseBody) });
httpRequestStub = sinon.stub().resolves({
body: JSON.stringify(mockResponseBody),
headers: {
"content-type": "application/json",
},
});

const { default: MockHttp } = proxyquire("../../src/protocols/Http", {
"min-req-promise": { request: httpRequestStub },
Expand Down Expand Up @@ -793,6 +796,7 @@ describe("HTTP networking module", () => {
open: sinon.stub(),
send: sinon.stub(),
setRequestHeader: sinon.stub(),
getResponseHeader: sinon.stub().returns("application/json"),
onreadystatechange: sinon.stub(),
timeout: 0,
};
Expand Down

0 comments on commit 16903e4

Please sign in to comment.