mirror of
https://github.com/owncast/owncast.git
synced 2024-11-24 21:59:43 +03:00
Derive chat display-name from upstream HTTP user header (#1633)
This commit is contained in:
parent
b2cd174676
commit
3963777660
2 changed files with 25 additions and 0 deletions
|
@ -58,6 +58,10 @@ func RegisterAnonymousChatUser(w http.ResponseWriter, r *http.Request) {
|
|||
// this is fine. register a new user anyway.
|
||||
}
|
||||
|
||||
if request.DisplayName == "" {
|
||||
request.DisplayName = r.Header.Get("X-Forwarded-User")
|
||||
}
|
||||
|
||||
newUser, err := user.CreateAnonymousUser(request.DisplayName)
|
||||
if err != nil {
|
||||
WriteSimpleResponse(w, false, err.Error())
|
||||
|
|
|
@ -38,3 +38,24 @@ test('can fetch chat messages', async (done) => {
|
|||
|
||||
done();
|
||||
});
|
||||
|
||||
test('can derive display name from user header', async (done) => {
|
||||
const res = await request
|
||||
.post('/api/chat/register')
|
||||
.set('X-Forwarded-User', 'test-user')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.displayName).toBe('test-user');
|
||||
done();
|
||||
});
|
||||
|
||||
test('can overwrite user header derived display name with body', async (done) => {
|
||||
const res = await request
|
||||
.post('/api/chat/register')
|
||||
.send({displayName: 'TestUserChat'})
|
||||
.set('X-Forwarded-User', 'test-user')
|
||||
.expect(200);
|
||||
|
||||
expect(res.body.displayName).toBe('TestUserChat');
|
||||
done();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue