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

Fixed members/signin_urls endpoint to take admin api key #21284

Merged
merged 25 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
595d255
Fix members/signin_urls endpoint to take api key
cathysarisky Oct 10, 2024
6a025af
Merge branch 'main' into fix-signin-by-api
cathysarisky Oct 10, 2024
33a7d99
try with a passing (but maybe still wrong?) filename
cathysarisky Oct 10, 2024
1b21b8a
Merge branch 'fix-signin-by-api' of https://github.com/cathysarisky/G…
cathysarisky Oct 10, 2024
c36c6e4
Merge branch 'main' into fix-signin-by-api
cathysarisky Oct 13, 2024
d86eceb
Merge branch 'main' into fix-signin-by-api
cathysarisky Oct 14, 2024
194d44b
Merge branch 'TryGhost:main' into fix-signin-by-api
cathysarisky Oct 14, 2024
67cc1f2
add a test
cathysarisky Oct 14, 2024
2ca0547
again a test?
cathysarisky Oct 14, 2024
b88ccc8
tests pass?
cathysarisky Oct 14, 2024
cda28d9
test frustration
cathysarisky Oct 14, 2024
2190022
tests pass locally?
cathysarisky Oct 14, 2024
1f53daf
403, not 401?
cathysarisky Oct 14, 2024
37471eb
tests failing and I'm stumped.
cathysarisky Oct 15, 2024
2f0ccf5
test
cathysarisky Oct 15, 2024
cd22851
lint
cathysarisky Oct 15, 2024
a1a2c32
Merge branch 'main' into fix-signin-by-api
cathysarisky Oct 15, 2024
c660e93
it works!
cathysarisky Oct 15, 2024
02cb6ad
Merge branch 'fix-signin-by-api' of https://github.com/cathysarisky/G…
cathysarisky Oct 15, 2024
6d5ac3b
ok, most of my tests pass...
cathysarisky Oct 15, 2024
41c476a
test tidy-up
cathysarisky Oct 15, 2024
4453497
Update ghost/core/core/server/data/migrations/versions/5.97/2023-10-1…
cathysarisky Oct 16, 2024
604a6ea
Merge branch 'main' into fix-signin-by-api
cathysarisky Oct 16, 2024
d421ab8
ah, lint
cathysarisky Oct 16, 2024
82a5e16
why did I think it was 2023?
cathysarisky Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {combineTransactionalMigrations, addPermissionToRole} = require('../../utils');

module.exports = combineTransactionalMigrations(
addPermissionToRole({
permission: 'Read member signin urls',
role: 'Admin Integration'
})
);
cathysarisky marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion ghost/core/core/server/data/schema/fixtures/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,8 @@
"link": "all",
"mention": "browse",
"collection": "all",
"recommendation": "all"
"recommendation": "all",
"member_signin_url": "read"
},
"Editor": {
"notification": "all",
Expand Down
1 change: 1 addition & 0 deletions ghost/core/test/integration/migrations/migration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ describe('Migrations', function () {
permissions.should.havePermission('Edit collections', ['Administrator', 'Editor', 'Admin Integration']);
permissions.should.havePermission('Add collections', ['Administrator', 'Editor', 'Author', 'Admin Integration']);
permissions.should.havePermission('Delete collections', ['Administrator', 'Editor', 'Admin Integration']);
permissions.should.havePermission('Read member signin urls', ['Administrator', 'Admin Integration']);
});

describe('Populate', function () {
Expand Down
56 changes: 56 additions & 0 deletions ghost/core/test/regression/api/admin/members-signin-url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,60 @@ describe('Members Sigin URL API', function () {
.expect(403);
});
});
describe('With an admin API key', function () {
let key, token;
before(async function () {
await localUtils.startGhost();
request = supertest.agent(config.get('url'));
await testUtils.initFixtures('members', 'api_keys');

const admin = await testUtils.createUser({
user: testUtils.DataGenerator.forKnex.createUser({email: '[email protected]'}),
role: testUtils.DataGenerator.Content.roles[0].name
});
request.user = admin;
cathysarisky marked this conversation as resolved.
Show resolved Hide resolved
key = testUtils.DataGenerator.Content.api_keys[0];
token = localUtils.getValidAdminToken('/admin/', key);
});
it('Cannot read without the key', function () {
return request
.get(localUtils.API.getApiQuery(`members/${testUtils.DataGenerator.Content.members[0].id}/signin_urls/`))
.set('Origin', config.get('url'))
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(403);
});
it('Can read with a key', function () {
return request
.get(localUtils.API.getApiQuery(`members/${testUtils.DataGenerator.Content.members[0].id}/signin_urls/`))
.set('Origin', config.get('url'))
.set('Content-Type', 'application/json')
.set('Authorization', `Ghost ${token}`)
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
.then((res) => {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.member_signin_urls);
jsonResponse.member_signin_urls.should.have.length(1);
localUtils.API.checkResponse(jsonResponse.member_signin_urls[0], 'member_signin_url');
});
});
it('Can read the members endpoint with a key (confirming token is ok!)', function () {
return request
.get(localUtils.API.getApiQuery(`members/`))
.set('Origin', config.get('url'))
.set('Authorization', `Ghost ${token}`)
.set('Content-Type', 'application/json')
.expect(200)
.then((res) => {
should.not.exist(res.headers['x-cache-invalidate']);
const jsonResponse = res.body;
should.exist(jsonResponse);
should.exist(jsonResponse.members);
jsonResponse.members.should.have.length(8);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('Migration Fixture Utils', function () {
const rolesAllStub = sinon.stub(models.Role, 'findAll').returns(Promise.resolve(dataMethodStub));

fixtureManager.addFixturesForRelation(fixtures.relations[0]).then(function (result) {
const FIXTURE_COUNT = 111;
const FIXTURE_COUNT = 112;
should.exist(result);
result.should.be.an.Object();
result.should.have.property('expected', FIXTURE_COUNT);
Expand Down
2 changes: 1 addition & 1 deletion ghost/core/test/unit/server/data/schema/integrity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = 'a4f016480ff73c6f52ee4c86482b45a7';
const currentFixturesHash = 'a489d615989eab1023d4b8af0ecee7fd';
const currentFixturesHash = '475f488105c390bb0018db90dce845f1';
const currentSettingsHash = '051ef2a50e2edb8723e89461448313cb';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';

Expand Down
1 change: 1 addition & 0 deletions ghost/core/test/utils/fixtures/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@
"webhook": "all",
"action": "all",
"member": "all",
"member_signin_url": "read",
"label": "all",
"email_preview": "all",
"email": "all",
Expand Down
Loading