@@ -51,10 +51,69 @@ public function test_authorize() {
51
51
$ _REQUEST ['micropub ' ] = 'endpoint ' ;
52
52
$ _POST ['access_token ' ] = $ token ;
53
53
$ authorize = new Indieauth_Local_Authorize ();
54
- $ user_id = $ authorize ->determine_current_user ( 0 );
54
+ $ user_id = $ authorize ->determine_current_user ( false );
55
55
$ this ->assertEquals ( $ user_id , self ::$ author_id );
56
56
}
57
57
58
+ public function test_authorize_bearer () {
59
+ $ token = self ::set_token ();
60
+ $ _REQUEST ['micropub ' ] = 'endpoint ' ;
61
+ $ _SERVER ['HTTP_AUTHORIZATION ' ] = 'Bearer ' . $ token ;
62
+ $ authorize = new Indieauth_Local_Authorize ();
63
+ $ authorize ->load ();
64
+ $ user_id = apply_filters ( 'determine_current_user ' , false );
65
+ $ this ->assertEquals ( $ user_id , self ::$ author_id );
66
+ }
67
+
68
+ public function test_authorize_bearer_other_non_matching_provider () {
69
+ $ token = self ::set_token ();
70
+ $ self_author_id = self ::$ author_id ;
71
+ add_filter ( 'determine_current_user ' , function ( $ user_id ) use ( $ self_author_id ) {
72
+ if ( 'Bearer other-valid-token ' === $ _SERVER ['HTTP_AUTHORIZATION ' ] ) {
73
+ return $ self_author_id + 1 ;
74
+ }
75
+ return $ user_id ;
76
+ } );
77
+ $ _REQUEST ['micropub ' ] = 'endpoint ' ;
78
+ $ _SERVER ['HTTP_AUTHORIZATION ' ] = 'Bearer ' . $ token ;
79
+ $ authorize = new Indieauth_Local_Authorize ();
80
+ $ authorize ->load ();
81
+ $ user_id = apply_filters ( 'determine_current_user ' , false );
82
+ $ this ->assertEquals ( $ user_id , self ::$ author_id );
83
+ }
84
+
85
+ public function test_authorize_bearer_other_provider () {
86
+ $ self_author_id = self ::$ author_id ;
87
+ add_filter ( 'determine_current_user ' , function ( $ user_id ) use ( $ self_author_id ) {
88
+ if ( 'Bearer other-valid-token ' === $ _SERVER ['HTTP_AUTHORIZATION ' ] ) {
89
+ return $ self_author_id ;
90
+ }
91
+ return $ user_id ;
92
+ } );
93
+ $ _REQUEST ['micropub ' ] = 'endpoint ' ;
94
+ $ _SERVER ['HTTP_AUTHORIZATION ' ] = 'Bearer other-valid-token ' ;
95
+ $ authorize = new Indieauth_Local_Authorize ();
96
+ $ authorize ->load ();
97
+ $ user_id = apply_filters ( 'determine_current_user ' , false );
98
+ $ this ->assertEquals ( $ user_id , self ::$ author_id );
99
+ }
100
+
101
+ public function test_authorize_bearer_no_valid_token_other_provider () {
102
+ $ self_author_id = self ::$ author_id ;
103
+ add_filter ( 'determine_current_user ' , function ( $ user_id ) use ( $ self_author_id ) {
104
+ if ( 'Bearer other-valid-token ' === $ _SERVER ['HTTP_AUTHORIZATION ' ] ) {
105
+ return $ self_author_id ;
106
+ }
107
+ return $ user_id ;
108
+ } );
109
+ $ _REQUEST ['micropub ' ] = 'endpoint ' ;
110
+ $ _SERVER ['HTTP_AUTHORIZATION ' ] = 'Bearer other-invalid-token ' ;
111
+ $ authorize = new Indieauth_Local_Authorize ();
112
+ $ authorize ->load ();
113
+ $ user_id = apply_filters ( 'determine_current_user ' , false );
114
+ $ this ->assertFalse ( $ user_id );
115
+ }
116
+
58
117
// Tests map_meta_cap for standard permissions
59
118
public function test_publish_posts_with_scopes () {
60
119
add_filter ( 'indieauth_scopes ' ,
0 commit comments