@@ -803,6 +803,7 @@ describe('Appservice', () => {
803
803
await verifyAuth ( "GET" , "/_matrix/app/v1/thirdparty/user" ) ;
804
804
await verifyAuth ( "GET" , "/_matrix/app/v1/thirdparty/location/protocolId" ) ;
805
805
await verifyAuth ( "GET" , "/_matrix/app/v1/thirdparty/location" ) ;
806
+ await verifyAuth ( "POST" , "/_matrix/app/unstable/org.matrix.msc3983/keys/claim" ) ;
806
807
} finally {
807
808
appservice . stop ( ) ;
808
809
}
@@ -1953,6 +1954,117 @@ describe('Appservice', () => {
1953
1954
1954
1955
} ) ;
1955
1956
1957
+ it ( 'should emit during MSC3983 key claim requests' , async ( ) => {
1958
+ const port = await getPort ( ) ;
1959
+ const hsToken = "s3cret_token" ;
1960
+ const appservice = new Appservice ( {
1961
+ port : port ,
1962
+ bindAddress : '' ,
1963
+ homeserverName : 'example.org' ,
1964
+ homeserverUrl : 'https://localhost' ,
1965
+ registration : {
1966
+ as_token : "" ,
1967
+ hs_token : hsToken ,
1968
+ sender_localpart : "_bot_" ,
1969
+ namespaces : {
1970
+ users : [ { exclusive : true , regex : "@_prefix_.*:.+" } ] ,
1971
+ rooms : [ ] ,
1972
+ aliases : [ ] ,
1973
+ } ,
1974
+ } ,
1975
+ } ) ;
1976
+ appservice . botIntent . ensureRegistered = ( ) => {
1977
+ return null ;
1978
+ } ;
1979
+
1980
+ await appservice . begin ( ) ;
1981
+
1982
+ try {
1983
+ const query = {
1984
+ "@alice:example.org" : {
1985
+ "DEVICEID" : [ "signed_curve25519" ] ,
1986
+ } ,
1987
+ } ;
1988
+ const response = {
1989
+ "@alice:example.org" : {
1990
+ "DEVICEID" : {
1991
+ "signed_curve25519:AAAAHg" : {
1992
+ "key" : "..." ,
1993
+ "signatures" : {
1994
+ "@alice:example.org" : {
1995
+ "ed25519:DEVICEID" : "..." ,
1996
+ } ,
1997
+ } ,
1998
+ } ,
1999
+ } ,
2000
+ } ,
2001
+ } ;
2002
+
2003
+ const claimSpy = simple . stub ( ) . callFn ( ( q , fn ) => {
2004
+ expect ( q ) . toStrictEqual ( query ) ;
2005
+ fn ( response ) ;
2006
+ } ) ;
2007
+ appservice . on ( "query.key_claim" , claimSpy ) ;
2008
+
2009
+ const res = await requestPromise ( {
2010
+ uri : `http://localhost:${ port } /_matrix/app/unstable/org.matrix.msc3983/keys/claim` ,
2011
+ method : "POST" ,
2012
+ qs : { access_token : hsToken } ,
2013
+ json : query ,
2014
+ } ) ;
2015
+ expect ( res ) . toStrictEqual ( response ) ;
2016
+ expect ( claimSpy . callCount ) . toBe ( 1 ) ;
2017
+ } finally {
2018
+ appservice . stop ( ) ;
2019
+ }
2020
+ } ) ;
2021
+
2022
+ it ( 'should return a 405 for MSC3983 if not used by consumer' , async ( ) => {
2023
+ const port = await getPort ( ) ;
2024
+ const hsToken = "s3cret_token" ;
2025
+ const appservice = new Appservice ( {
2026
+ port : port ,
2027
+ bindAddress : '' ,
2028
+ homeserverName : 'example.org' ,
2029
+ homeserverUrl : 'https://localhost' ,
2030
+ registration : {
2031
+ as_token : "" ,
2032
+ hs_token : hsToken ,
2033
+ sender_localpart : "_bot_" ,
2034
+ namespaces : {
2035
+ users : [ { exclusive : true , regex : "@_prefix_.*:.+" } ] ,
2036
+ rooms : [ ] ,
2037
+ aliases : [ ] ,
2038
+ } ,
2039
+ } ,
2040
+ } ) ;
2041
+ appservice . botIntent . ensureRegistered = ( ) => {
2042
+ return null ;
2043
+ } ;
2044
+
2045
+ await appservice . begin ( ) ;
2046
+
2047
+ try {
2048
+ const query = {
2049
+ "@alice:example.org" : {
2050
+ "DEVICEID" : [ "signed_curve25519" ] ,
2051
+ } ,
2052
+ } ;
2053
+
2054
+ // Note how we're not registering anything with the EventEmitter
2055
+
2056
+ const res = await requestPromise ( {
2057
+ uri : `http://localhost:${ port } /_matrix/app/unstable/org.matrix.msc3983/keys/claim` ,
2058
+ method : "POST" ,
2059
+ qs : { access_token : hsToken } ,
2060
+ json : query ,
2061
+ } ) . catch ( e => ( { body : e . response . body , statusCode : e . statusCode } ) ) ;
2062
+ expect ( res ) . toStrictEqual ( { statusCode : 405 , body : { errcode : "M_UNRECOGNIZED" , error : "Endpoint not implemented" } } ) ;
2063
+ } finally {
2064
+ appservice . stop ( ) ;
2065
+ }
2066
+ } ) ;
2067
+
1956
2068
it ( 'should emit while querying users' , async ( ) => {
1957
2069
const port = await getPort ( ) ;
1958
2070
const hsToken = "s3cret_token" ;
0 commit comments