对于我的生活,我无法理解为什么以下导致false允许写入.假设我的users集合是空的,我正在从我的Angular前端编写以下表单的文档:
{
displayName: 'FooBar',
email: 'foo.bar@example.com'
}
Run Code Online (Sandbox Code Playgroud)
我目前的安全规则:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
function isAdmin() {
return resource.data.role == 'ADMIN';
}
function isEditingRole() {
return request.resource.data.role != null;
}
function isEditingOwnRole() {
return isOwnDocument() && isEditingRole();
}
function isOwnDocument() {
return request.auth.uid == userId;
}
allow read: if isOwnDocument() || isAdmin();
allow write: if !isEditingOwnRole() && (isOwnDocument() || isAdmin());
}
}
}
Run Code Online (Sandbox Code Playgroud)
一般来说,我希望没有用户能够编辑自己的角色.普通用户可以编辑自己的文档,管理员可以编辑任何人.
Stubbing isEditingRole()for false给出了预期的结果,所以我把它缩小到那个表达式.
写入不断变回虚假,我无法确定原因.任何想法或修复都会有所帮助!
编辑1
我试过的事情:
function …Run Code Online (Sandbox Code Playgroud) 我正在尝试理解TypeScript装饰器(特别是属性),并根据我看到的一些示例提出了以下代码:
decorator.ts
export function logProperty(target: any, key: string) {
let val = this[key];
const getter = () => {
console.log(`Get: ${key} => ${val}`);
return val;
};
const setter = (newVal) => {
console.log(`Set: ${key} => ${newVal}`);
val = newVal;
};
if (delete this[key]) {
Object.defineProperty(target, key, {
get: getter,
set: setter,
enumerable: true,
configurable: true
});
}
}
Run Code Online (Sandbox Code Playgroud)
main.ts
import { logProperty } from './decorators';
class Person {
@logProperty
firstName: string;
@logProperty
lastName: string;
constructor(firstName: string, lastName: string) {
this.firstName …Run Code Online (Sandbox Code Playgroud) 我有一个AbstractAuthenticationProcessingFilter我用来处理路径上的POST请求/sign-in.CORS预检请求返回404,因为没有匹配的路径.这对我来说很有意义.
我想知道的是,如果有一种方法可以通知Spring有一个过滤器处理POST(而不是一个控制器),那么Spring可以像控制器处理POST一样调度OPTIONS .用一个控制器写一个控制器是不好的做法PostMapping?我不确定这样做会怎么样,因为技术上过滤器处理POST.
谢谢你的帮助!
更新
这是我的设置.我最初是从手机发布的,因此无法添加这些详细信息.见下文.重申一下,没有控制器/sign-in.POST由JwtSignInFilter.处理.
CORS配置
@EnableWebMvc
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*") // TODO: Lock this down before deploying
.allowedHeaders("*")
.allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.DELETE.name())
.allowCredentials(true);
}
}
Run Code Online (Sandbox Code Playgroud)
安全配置
@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public JwtSignInFilter signInFilter() throws Exception {
return new JwtSignInFilter(
new AntPathRequestMatcher("/sign-in", HttpMethod.POST.name()),
authenticationManager()
);
}
@Bean
public JwtAuthenticationFilter authFilter() {
return new JwtAuthenticationFilter(); …Run Code Online (Sandbox Code Playgroud) 我有一个来自 control 的自定义选择器app-date-picker。它实现了ControlValueAccessor. 我有一个名为的组件MyPage,其中包含此自定义表单控件:
<app-date-picker class="address__from-date" [(ngModel)]="fromDate"></app-date-picker>
Run Code Online (Sandbox Code Playgroud)
我正在尝试编写一个单元测试来MyPage测试绑定的两个方向。我已经对其他表单字段执行了此操作,效果很好,例如:
it('should bind zip code', fakeAsync(() => {
const formControl = element.query(By.css('.address__zip-code input')).nativeElement;
// model -> view
component.zipCode = 76777;
fixture.detectChanges();
tick();
expect(formControl.value).toEqual('76777');
// view -> model
formControl.value = '89556';
formControl.dispatchEvent(new Event('input'));
expect(component.zipCode).toEqual(89556);
}));
Run Code Online (Sandbox Code Playgroud)
当我尝试为自定义表单控件执行此操作时,出现了问题。到目前为止,我只能测试一个绑定方向,即使如此,它也需要使用ng-reflect-model,这太糟糕了:
it('should bind from-date', fakeAsync(() => {
const formControl = element.query(By.css('.address__from-date app-date-picker')).nativeElement;
// model -> view
component.fromDate = '01/2017';
fixture.detectChanges();
tick();
expect(formControl.attributes['ng-reflect-model'].value).toEqual('01/2017');
// view -> model
// Not sure …Run Code Online (Sandbox Code Playgroud) unit-testing angular2-forms angular2-testing angular angular-forms
angular ×1
cors ×1
decorator ×1
firebase ×1
javascript ×1
jwt ×1
properties ×1
spring ×1
this ×1
typescript ×1
unit-testing ×1