-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78bb742
commit 2373018
Showing
52 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ const mocks = { | |
(id === '[email protected]' && namespace === 'garden-foo') | ||
break | ||
case 'projects': | ||
allowed = id === '[email protected]' | ||
allowed = id === '[email protected]' || id === '[email protected]' | ||
break | ||
} | ||
} | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,36 @@ exports[`api events when user is "admin" should subscribe unhealthy shoots for a | |
] | ||
`; | ||
|
||
exports[`api events when user is "admin" should synchronize a project 1`] = ` | ||
[ | ||
{ | ||
"metadata": { | ||
"name": "bar", | ||
"resourceVersion": "42", | ||
"uid": 2, | ||
}, | ||
"spec": { | ||
"createdBy": { | ||
"apiGroup": "rbac.authorization.k8s.io", | ||
"kind": "User", | ||
"name": "[email protected]", | ||
}, | ||
"description": "bar-description", | ||
"namespace": "garden-bar", | ||
"owner": { | ||
"apiGroup": "rbac.authorization.k8s.io", | ||
"kind": "User", | ||
"name": "[email protected]", | ||
}, | ||
"purpose": "bar-purpose", | ||
}, | ||
"status": { | ||
"phase": "Ready", | ||
}, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`api events when user is "foo" should subscribe shoots for a single cluster 1`] = ` | ||
[ | ||
[ | ||
|
@@ -343,6 +373,33 @@ exports[`api events when user is "foo" should subscribe shoots for a single name | |
] | ||
`; | ||
|
||
exports[`api events when user is "foo" should subscribe shoots for a single namespace 2`] = ` | ||
[ | ||
[ | ||
{ | ||
":authority": "kubernetes:6443", | ||
":method": "post", | ||
":path": "/apis/authorization.k8s.io/v1/selfsubjectaccessreviews", | ||
":scheme": "https", | ||
"authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZvb0BleGFtcGxlLm9yZyIsImlhdCI6MTU3NzgzNjgwMCwiYXVkIjpbImdhcmRlbmVyIl0sImV4cCI6MzE1NTcxNjgwMCwianRpIjoianRpIn0.k3kGjF6AgugJLdwERXEWZPaibFAPFPOnmpT3YM9H0xU", | ||
}, | ||
{ | ||
"apiVersion": "authorization.k8s.io/v1", | ||
"kind": "SelfSubjectAccessReview", | ||
"spec": { | ||
"nonResourceAttributes": undefined, | ||
"resourceAttributes": { | ||
"group": "core.gardener.cloud", | ||
"namespace": "garden-foo", | ||
"resource": "shoots", | ||
"verb": "list", | ||
}, | ||
}, | ||
}, | ||
], | ||
] | ||
`; | ||
|
||
exports[`api events when user is "foo" should subscribe shoots for all namespace 1`] = ` | ||
[ | ||
[ | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,11 @@ const watches = require('../lib/watches') | |
const cache = require('../lib/cache') | ||
const tickets = require('../lib/services/tickets') | ||
const SyncManager = require('../lib/github/SyncManager') | ||
const { sha256 } = require('../lib/io/helper') | ||
|
||
const { cloneDeep } = require('lodash') | ||
|
||
const flushPromises = () => new Promise(setImmediate) | ||
|
||
const rooms = new Map() | ||
|
||
|
@@ -48,8 +53,45 @@ const nsp = { | |
emit: jest.fn(), | ||
} | ||
|
||
const sockets = [ | ||
{ | ||
id: 1, | ||
data: { | ||
user: { | ||
id: '[email protected]', | ||
profiles: { | ||
canListProjects: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
id: 2, | ||
data: { | ||
user: { | ||
id: '[email protected]', | ||
profiles: { | ||
canListProjects: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
id: 3, | ||
data: { | ||
user: { | ||
id: '[email protected]', | ||
profiles: { | ||
canListProjects: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
] | ||
|
||
const io = { | ||
of: jest.fn().mockReturnValue(nsp), | ||
fetchSockets: jest.fn().mockResolvedValue(sockets), | ||
} | ||
|
||
describe('watches', function () { | ||
|
@@ -163,6 +205,61 @@ describe('watches', function () { | |
}) | ||
}) | ||
|
||
describe('projects', function () { | ||
it('should watch projects', async function () { | ||
watches.projects(io, informer) | ||
|
||
expect(io.of).toHaveBeenCalledTimes(1) | ||
expect(io.of.mock.calls).toEqual([['/']]) | ||
|
||
const uid = 4 | ||
const bar = { | ||
metadata: { | ||
name: 'bar', | ||
uid, | ||
}, | ||
spec: { | ||
members: [{ | ||
kind: 'User', | ||
name: '[email protected]', | ||
}], | ||
}, | ||
} | ||
|
||
informer.emit('add', bar) | ||
const modifiedBar = cloneDeep(bar) | ||
modifiedBar.spec.members = [] | ||
informer.emit('update', modifiedBar, bar) | ||
informer.emit('delete', modifiedBar) | ||
|
||
await flushPromises() | ||
|
||
expect(logger.error).not.toHaveBeenCalled() | ||
|
||
const ids = [ | ||
'[email protected]', | ||
'[email protected]', | ||
].map(sha256) | ||
expect(Array.from(rooms.keys())).toEqual(ids) | ||
expect(nsp.to).toHaveBeenCalledTimes(5) | ||
|
||
const adminRoom = rooms.get(ids[0]) | ||
expect(adminRoom.emit).toHaveBeenCalledTimes(3) | ||
expect(adminRoom.emit.mock.calls).toEqual([ | ||
['projects', { type: 'ADDED', uid }], | ||
['projects', { type: 'MODIFIED', uid }], | ||
['projects', { type: 'DELETED', uid }], | ||
]) | ||
|
||
const fooRoom = rooms.get(ids[1]) | ||
expect(fooRoom.emit).toHaveBeenCalledTimes(2) | ||
expect(fooRoom.emit.mock.calls).toEqual([ | ||
['projects', { type: 'ADDED', uid }], | ||
['projects', { type: 'DELETED', uid }], | ||
]) | ||
}) | ||
}) | ||
|
||
describe('leases', function () { | ||
const metadata = { | ||
projectName: 'foo', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters